我想在图表(AchartEngine)中显示ArrayList值。我从JSON webservice获得了ArrayList值。如何使用arraylist字符串值显示图形数据?是否有任何转换整个arraylist值的方法?
JSONObject jObject = JSONParser.getJsonFromURL(temp_url);
String flag = jObject.getString("Flag");
JSONArray jArray = jObject.getJSONArray("TempTransList");
for(int i=0;i<jArray.length();i++){
JSONObject job = jArray.getJSONObject(i);
String BuildingId = job.getString("BuildingId");
String BuildingSegmentId = job.getString("BuildingSegmentId");
..String Customer_ID = job.getString("Customer_ID");
String DateTime = job.getString("DateTime");
//String InnerLocationId = job.getString("InnerLocationId");
String Temp_Date = job.getString("TempDate");
String Temp_Time = job.getString("TempTime");
String Temperature = job.getString("Temperature");
temp_details.add(Temperature);
date_time.add(DateTime);
temp_date.add(Temp_Date);
temp_time.add(Temp_Time);
图表初始化代码:
private void initializeChartNew() {
// Creating an XYSeries for Income
XYSeries fromTemp = new XYSeries("From Temperature");
// Creating an XYSeries for Expense
XYSeries toTemp = new XYSeries("To Temperature");
arrayX = new double[temp_time.size()];
from_date = new double[date_time.size()];
to_date = new double[temp_date.size()];
for (int i = 0; i < temp_time.size(); i++) {
fromTemp.add(arrayX[i], from_date[i]);
toTemp.add(arrayX[i], to_date[i]);
//System.out.println("value of arrayX "+arrayX);
//System.out.println("value of from_date "+from_date);
//System.out.println("value of to_date "+to_date);
}
System.out.println("value of temp_time "+temp_time.size());
System.out.println("value of arrayX "+arrayX);
System.out.println("value of from_date "+from_date);
System.out.println("value of to_date "+to_date);
// Creating a dataset to hold each series
dataset = new XYMultipleSeriesDataset();
// Adding Income Series to the dataset
dataset.addSeries(fromTemp);
// Adding Expense Series to dataset
dataset.addSeries(toTemp);
// Creating XYSeriesRenderer to customize incomeSeries
XYSeriesRenderer from_tempRenderer = new XYSeriesRenderer();
from_tempRenderer.setColor(Color.WHITE);
from_tempRenderer.setPointStyle(PointStyle.CIRCLE);
from_tempRenderer.setFillPoints(true);
from_tempRenderer.setLineWidth(2);
from_tempRenderer.setDisplayChartValues(true);
// Creating XYSeriesRenderer to customize expenseSeries
XYSeriesRenderer to_tempRenderer = new XYSeriesRenderer();
to_tempRenderer.setColor(Color.YELLOW);
to_tempRenderer.setPointStyle(PointStyle.CIRCLE);
to_tempRenderer.setFillPoints(true);
to_tempRenderer.setLineWidth(2);
to_tempRenderer.setDisplayChartValues(true);
// Creating a XYMultipleSeriesRenderer to customize the whole chart
multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setAxisTitleTextSize(16);
multiRenderer.setChartTitleTextSize(16);
multiRenderer.setLabelsTextSize(12);
multiRenderer.setLegendTextSize(12);
multiRenderer.setXLabels(0);
multiRenderer.setChartTitle("Temperature Detail");
multiRenderer.setXTitle("Time");
multiRenderer.setYTitle("Temperature");
multiRenderer.setZoomButtonsVisible(true);
for (int i = 0; i < temp_details.size(); i++) {
multiRenderer.addXTextLabel(i, temp_details.get(i));
System.out.println("value of temp_details name " + temp_details.get(i));
}
System.out.println("value of temp_details " + temp_details.size());
// Adding incomeRenderer and expenseRenderer to multipleRenderer
// Note: The order of adding dataseries to dataset and renderers to
// multipleRenderer
// should be same
multiRenderer.addSeriesRenderer(from_tempRenderer);
multiRenderer.addSeriesRenderer(to_tempRenderer);
}
答案 0 :(得分:2)
Try this one
for (int i = 0; i <= mList.size(); i++) {
multiRenderer.addXTextLabel(i, mList.get(i));
}