开发者

How to interval between values of x-axis and y-axis using achartEngine

I am using aChartEngine for graphs in android everything is fine till now...Now i wanna set the time interval between the axes values like x-axis values time interval should be 1.5 so x-axis values will be

0, 1.5, 3, 4.5 etc...

Can anybody tell me how to set the time interval....

public class LineGraphDemo extends Activity {
XYMultipleSeriesDataset mDataSet;
XYMultipleSeriesRenderer mRenderer;
private GraphicalView mView;
List<double[]> values=new ArrayList<double[]>();
List<Date[]> dates=new ArrayList<Date[]>();
private Date[] mDate;
String s;
Date d=new Date();
protected void onCreate(Bundle si){
    super.onCreate(si);
    setContentView(R.layout.list1);


     s = DateFormat.format("hh:mm:ss ", d.getTime()).toString();

    String str=SimpleTimeZone.getTimeZone(TimeZone.getAvailableIDs().toString()).toString();
    Log.e("System date",s+"  "+"  "+str);


    mDate=new Date[]{new Date(110,10,5),new Date(109,6,1)};
     values.add(new double[] { 142, 123, 142, 152, 149, 122, 110, 120, 125, 155, 146, 150 });
    mDataSet=getDataSet(values);
    mRenderer=getRenderer();



}
public void onResume(){
    super.onResume();
    if(mView==null){
    LinearLayout lay=(LinearLayout)findViewById(R.id.chart);

    mView=ChartFactory.getTimeChartView(getApplicationContext(), mDataSet,mRenderer,"a");

    lay.ad开发者_JAVA技巧dView(mView);
    }else{
        mView.repaint();
    }
}
protected XYMultipleSeriesRenderer getRenderer(){
    XYMultipleSeriesRenderer renderer=new XYMultipleSeriesRenderer();
    renderer.setYLabelsAlign(Align.RIGHT);
    renderer.setAxisTitleTextSize(16);
    renderer.setChartTitleTextSize(20);
    renderer.setLabelsTextSize(15);
    renderer.setLegendTextSize(15);
    renderer.setPointSize(5f);
    renderer.setMargins(new int[] { 20, 30, 15, 0 });
    renderer.setChartTitle("Line Graph");
    renderer.setXTitle("x-axis");
    renderer.setYTitle("y-axis");
    //renderer.setXAxisMin(-2);
    //renderer.setXAxisMax(14);
    renderer.setXAxisMin(mDate[0].getTime());        renderer.setXAxisMax(mDate[mDate.length-1].getTime());
    renderer.setYAxisMin(50);
    renderer.setYAxisMax(200);
    renderer.setXLabels(6);
    renderer.setYLabels(10);
    renderer.setAxesColor(Color.GREEN);
    renderer.setLabelsColor(Color.MAGENTA);
    renderer.setDisplayChartValues(true);

    XYSeriesRenderer r = new XYSeriesRenderer();
    r.setColor(Color.YELLOW);
    r.setPointStyle(PointStyle.DIAMOND);
    renderer.addSeriesRenderer(r);

    return renderer;
}
protected XYMultipleSeriesDataset getDataSet(List<double[]> values){
    XYMultipleSeriesDataset dataSet=new XYMultipleSeriesDataset();
    CategorySeries series=new CategorySeries("mobile");
    for (int k = 0; k < values.size(); k++) {
          double[] xV=values.get(k);
          int seriesLen=xV.length;
          for(int l=0;l<seriesLen;l++){
            series.add(xV[l]);
        }
    }
    dataSet.addSeries(series.toXYSeries());
    return dataSet;
}

}

This is my class now i want to set the interval between the dates...and it is not showing the graph...

Thanks... Ammu


@Ammu there are two ways i will tell you the easiest way you can use labels to set the axis values like renderer.addTextLabel(position,"string to be displayed"); if you are not able to get it i will tell you the second way

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜