我正在使用achartengine库forline graph。而不是时间戳如何在x轴上显示日期
我的代码是
public GraphicalView getLine(Context context, LinkedHashMap<String, List<Item>> data, String value2, String value3) {
List<TimeSeries> series=new ArrayList<TimeSeries>();
Set<String> keys = data.keySet();
for(String key:keys)
{
TimeSeries series1 = new TimeSeries(key);
List<Item> value=data.get(key);
for(Item itm:value)
{
Double temp=Double.parseDouble(itm.getDataItem(value3));
String temp1=null;
if(value2.equals("created_time"))
{
temp1=itm.getCreated_time();
}
else
{
try
{
temp1=itm.getModified_time();
}
catch (NullPointerException e) {
temp1=itm.getCreated_time();
}
}
Timestamp timestamp = new Timestamp(Integer.parseInt(temp1.substring(0,10)));
Date date = new Date(timestamp.getTime()*1000);
series1.add(date,temp);
}
series.add(series1);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
for(TimeSeries serie:series)
{
dataset.addSeries(serie);
}
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer(); // Holds a collection of XYSeriesRenderer and customizes the graph
mRenderer.setBackgroundColor(Color.BLACK);
mRenderer.setZoomEnabled(true);
mRenderer.setAntialiasing(true);
for(TimeSeries serie:series)
{
XYSeriesRenderer renderer = new XYSeriesRenderer(); // This will be used to customize line 1
mRenderer.addSeriesRenderer(renderer);
int color;
Random rnd = new Random();
color = Color.argb(200, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
renderer.setColor(color);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
}
return ChartFactory.getLineChartView(context, dataset, mRenderer);
}
答案 0 :(得分:0)
您可以设置自定义标签:
renderer.addXTextLabel(x, formattedDate);
答案 1 :(得分:0)
我找到了更好的解决方案
ChartFactory.getTimeChartView(context, dataset,mRenderer, "DD-MM-YYY");