我正在创建一个折线图,其中X轴为日期,Y轴为double值。以前我的X轴只包含整数,然后图表可见。现在只显示带有x和Y轴的布局。我该如何解决这个问题?
public class GraphActivity extends Activity {
private GraphicalView mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
Bundle extras=getIntent().getExtras();
double[] TArray=extras.getDoubleArray("tempArray");
Log.d("1000", String.valueOf(TArray.length));
String[] TSArray=extras.getStringArray("dateArray");
Log.d("1002", String.valueOf(TSArray.length));
int dateArraySize=TArray.length;
Date dateArray[]=new Date[TArray.length];
String[] targetArr = TSArray;
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
for (int i=0;i<TArray.length;i++)
{
Date result = null;
try {
result = df.parse(targetArr[i]);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dateArray[i]=result;
}
for(Date element:dateArray){
Log.d("1005", element.toString());
}
TimeSeries series=new TimeSeries("Temperature");
for(int i=0;i<TArray.length;i++){
try{
series.add(dateArray[i],TArray[i]);
Log.i("series_add1:", "fyn");
}catch(Exception ex){
Log.e("series_add2", "not added to the timeseries");
}
}
XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
Log.d("dataset1", "before adding to dataset");
dataset.addSeries(series);
Log.d("dataset2", "after adding to dataset");
//properties of line
XYSeriesRenderer renderer =new XYSeriesRenderer();
renderer.setColor(Color.YELLOW);
renderer.setPointStyle(PointStyle.DIAMOND);
renderer.setFillPoints(true);
final NumberFormat tempValueFormat=new DecimalFormat("##.##");
renderer.setChartValuesFormat(tempValueFormat);
renderer.setChartValuesTextSize(20);
renderer.setDisplayChartValues(true);
renderer.setChartValuesSpacing((float)0.5);
renderer.setChartValuesTextSize(20);
XYMultipleSeriesRenderer mRenderer=new XYMultipleSeriesRenderer();
mRenderer.setXRoundedLabels(false);
mRenderer.addSeriesRenderer(renderer);
mRenderer.setBackgroundColor(Color.BLACK);
mRenderer.setPointSize(5);
mRenderer.setLabelsColor(Color.GREEN);
mRenderer.setChartTitle("TEMPERATURE LINE GRAPH");
mRenderer.setChartTitleTextSize(30);
mRenderer.setAxesColor(Color.WHITE);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setAxisTitleTextSize(25);
mRenderer.setXTitle("TIME");
mRenderer.setYTitle("TEMPERATURE");
mRenderer.setZoomButtonsVisible(true);
mRenderer.setXLabelsAngle(10);
mRenderer.setYLabelsAlign(Align.LEFT);
mRenderer.setYLabels(15);
mRenderer.setXLabels(15);
mRenderer.setXLabelsAlign(Align.RIGHT);
mRenderer.setYLabelsAngle(10);
mRenderer.setXAxisMin(0);
mRenderer.setXAxisMax(30);
mRenderer.setShowGridX(true);
mRenderer.setShowGridY(true);
/* for(int i=0;i<tempArray.length;i++)
{
mRenderer.addXTextLabel(i, " :temp");
}
*/ LinearLayout layout=(LinearLayout)findViewById(R.id.lineGraph);
mChart = (GraphicalView)ChartFactory.getTimeChartView(this, dataset,mRenderer,"dd-MM-yyyy hh:mm:ss");
layout.addView(mChart);
if(mChart==null){
Log.i("mChart: ", "null");
}
else{
Log.i("mChart: ", "not null but not displaying graph");
}
}
}