android – 如何使用AchartEngine在折线图中设置x轴上的日期?
作者:互联网
我已尝试在SO上发布各种链接,但没有得到可靠的答案.
这是我的代码:
TimeSeries series = new TimeSeries("Burned Calories");
for (int i = 0; i < x_axis.size(); i++) {
String date = x_axis.get(i);
int y = Integer.parseInt(y_axis.get(i));
Date d;
try {
d = df.parse(date);
series.add(d, y);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYSeriesRenderer render = new XYSeriesRenderer();
render.setColor(Color.GREEN);
render.setPointStyle(PointStyle.SQUARE);
render.setFillPoints(true);
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.addSeriesRenderer(render);
renderer.setChartTitle("Line Chart");
renderer.setAxesColor(Color.BLUE);
renderer.setGridColor(Color.WHITE);
renderer.setShowGrid(true);
renderer.setShowAxes(true);
renderer.setShowGridX(true);
renderer.setShowGridY(true);
renderer.setShowLabels(true);
renderer.setPanEnabled(true, true);
renderer.setFitLegend(true);
renderer.setXTitle("Date");
renderer.setAxisTitleTextSize(15);
renderer.setXLabelsAlign(Align.CENTER);
renderer.setYTitle("Values");
chart = ChartFactory.getLineChartView(this, dataset, renderer);
我在x轴上得到奇怪的值.
任何帮助,将不胜感激.
解决方法:
这些是我在我的代码中所做的基本更改,它对我有用..
TimeSeries series2 = new TimeSeries("Protein");
for (int i = 0; i < x_axis.size(); i++) {
int y = Integer.parseInt(y1_axis.get(i));
// Adding y as protein value
series2.add(i + 1, y);
}
for (int i = 0; i < x_axis.size(); i++) {
renderer.addXTextLabel(i + 1, x_axis.get(i));
}
renderer.setXLabels(0);
标签:achartengine,linechart,android 来源: https://codeday.me/bug/20190901/1785262.html