English 中文(简体)
如何使用achartEngine在x轴和y轴的值之间进行间隔
原标题:How to interval between values of x-axis and y-axis using achartEngine

我正在android中使用aChartEngine绘制图形,到目前为止一切都很好。。。现在我想设置轴值之间的时间间隔,比如x轴值,时间间隔应该是1.5,所以x轴值将是

0、1.5、3、4.5等。。。

有人能告诉我如何设置时间间隔吗。。。。

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.addView(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;
}

}

这是我的课,现在我想设置日期之间的间隔。。。它并没有显示图表。。。

Thanks... Ammu

问题回答

@Ammu有两种方法,我会告诉你最简单的方法,你可以使用标签来设置轴值,比如renderer.addTextLabel(位置,“要显示的字符串”);如果你拿不到,我会告诉你第二条路





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签