2014-06-20 60 views
0

我正在使用achartengine 1.1.0.jar開發折線圖。在android中有自定義y軸空間問題的折線圖問題

我在繪製最終折線圖時遇到了一個問題。

繪製的y軸標籤沒有標籤和所有標籤之間的垂直間距。

我附上了繪製的折線圖的截圖。

line chart

我在這裏也安裝代碼片段吧。

package com.example.simplelinecharexample; 

import org.achartengine.ChartFactory; 
import org.achartengine.GraphicalView; 
import org.achartengine.chart.PointStyle; 
import org.achartengine.model.XYMultipleSeriesDataset; 
import org.achartengine.model.XYSeries; 
import org.achartengine.renderer.XYMultipleSeriesRenderer; 
import org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation; 
import org.achartengine.renderer.XYSeriesRenderer; 

import android.app.Activity; 
import android.graphics.Color; 
import android.graphics.Paint.Align; 
import android.os.Bundle; 
import android.widget.LinearLayout; 

public class main extends Activity GraphicalView mChart;

private String[] mMonth = new String[] { "Jan", "Feb", "Mar", "Apr", "May", 
     "Jun", 

     "Jul", "Aug" }; 
private String[] mweek = new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", 
     "Sat", 

     "Sun" }; 
private String[] steps = new String[31]; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    for (int i = 0; i <= 15; i++) 
     if (i == 0) 
      steps[i] = String.valueOf(0); 
     else 
      steps[i] = String.valueOf(Integer.parseInt(steps[i - 1]) + 2000); 
    OpenChart(); 
} 

private void OpenChart() { 
    int z[] = { 0, 1, 2, 3, 4, 5, 6, 7}; 
// int x[] = { 10, 18, 32, 21, 48, 60, 53, 80 }; 
    int[] income = { 2000, 2500, 2700, 3000, 2800, 3500,5000 , 15000}; 
    XYSeries xSeries = new XYSeries("X Series"); 
    for (int i = 0; i < z.length; i++) { 
     xSeries.add(z[i], income[i]); 
    } 
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); 
    dataset.addSeries(xSeries); 

    XYSeriesRenderer Xrenderer = new XYSeriesRenderer(); 
    Xrenderer.setColor(Color.RED); 
    Xrenderer.setPointStyle(PointStyle.DIAMOND); 
    Xrenderer.setDisplayChartValues(true); 
    Xrenderer.setLineWidth(5); 
    Xrenderer.setFillPoints(true); 

    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); 

    mRenderer.setChartTitle("X Vs Y Chart");`enter code here` 
    mRenderer.setXTitle("X Values"); 
    mRenderer.setYTitle("Y Values"); 
    mRenderer.setXLabels(0);![enter image description here][2] 
    mRenderer.setShowGrid(true); 
    mRenderer.setYLabels(49); 

    for (int i = 0; i < mweek.length; i++) { 
     mRenderer.addXTextLabel(i, mweek[i]); 
    } 
    mRenderer.addSeriesRenderer(Xrenderer); 
    mRenderer.setXLabelsAlign(Align.LEFT); 
    mRenderer.setYLabelsAlign(Align.RIGHT); 
    mRenderer.setLabelsTextSize(20); 
    mRenderer.setYAxisMin(0); 
    mRenderer.setXAxisMin(-1); 
    mRenderer.setYAxisMax(98000); 
    mRenderer.setPanEnabled(false, true); 
    mRenderer.setPanLimits(new double[]{0.0,Double.MAX_VALUE,0.0,98000}); 
    mRenderer.setZoomEnabled(true, false); 
    mRenderer.setAntialiasing(true); 

    mRenderer.setMargins(new int[] { 60, 120, 60, 60 }); 
    LinearLayout chart_container = (LinearLayout) findViewById(R.id.Chart_layout); 
    mChart = (GraphicalView) ChartFactory.getLineChartView(
      getBaseContext(), dataset, mRenderer); 

    chart_container.addView(mChart); 
} 

}

我要添加Y軸標籤之間的垂直空間,它應該自動滾動。

回答

1

只需更換您的線路 mRenderer.setYLabels(49);

mRenderer.setYLabels(10);

當您減小SetYlabels的大小時,它將增加Y標籤之間的間距。

享受...