我遇到了一些问题,如果我有一个图表行只有原告,如果我试图显示单个图表行,那么图表行将不可见。它就像显示任何一行的最小值是两个。这是我的代码:
package com.achartengine.chart;
import static com.CommonUtilities.DEBUG;
import static com.CommonUtilities.TAG;
import java.util.ArrayList;
import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.RangeCategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import com.work;
import com.workSummary;
import com.worksDataSource;
import com.worksSummaryDataSource;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint.Align;
import android.util.Log;
/**
* Temperature demo range chart.
*/
public class TemperatureChart extends AbstractDemoChart {
/**
* Returns the chart name.
*
* @return the chart name
*/
public String getName() {
return "Temperature range chart";
}
/**
* Returns the chart description.
*
* @return the chart description
*/
public String getDesc() {
return "The monthly temperature (vertical range chart)";
}
/**
* Executes the chart demo.
*
* @param context the context
* @return the built intent
*/
public Intent execute(Context context) {
if (DEBUG) Log.i(TAG, "TemperatureChart Intent execute");
worksSummaryDataSource worksSummaryDataSource;
worksSummaryDataSource = new worksSummaryDataSource(context);
worksSummaryDataSource.open();
ArrayList<workSummary> workSummaries = new ArrayList<workSummary>();
workSummaries = worksSummaryDataSource.getAllworksSummary();
if (DEBUG) Log.i(TAG, "TemperatureChart Intent execute got workSummaries");
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
RangeCategorySeries series = new RangeCategorySeries("works");
int[] colors = new int[] { Color.CYAN };
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
worksDataSource datasource = new worksDataSource(context);
datasource.open();
work work = new work();
worksDataSource worksDataSource = new worksDataSource(context);
worksDataSource.open();
int w = 0;
if (DEBUG) Log.i(TAG, "workSummaries.size(): "+workSummaries.size());
for (int i = 0; i < workSummaries.size(); i++) {
if (DEBUG) Log.i(TAG, "TemperatureChart Intent execute workSummaries id: "+String.valueOf(workSummaries.get(i).work_id));
for (int j = 0; j < workSummaries.get(i).summary.size(); j++) {
w++;
Double down = workSummaries.get(i).summary.get(j).uptime - 100;
Double up = workSummaries.get(i).summary.get(j).uptime;
series.add(down.intValue(), up.intValue());
work = worksDataSource.getByworkId(String.valueOf(workSummaries.get(i).work_id));
renderer.addXTextLabel(w, work.getTitle() + " - " + workSummaries.get(i).summary.get(j).service_name);
if (DEBUG) Log.i(TAG, "TemperatureChart Intent execute workSummaries service_name: "+workSummaries.get(i).summary.get(j).service_name);
if (DEBUG) Log.i(TAG, "TemperatureChart Intent execute workSummaries result: "+down +" "+ up);
}
}
if(w == 1){
series.add(0, 0);
}
worksDataSource.close();
dataset.addSeries(series.toXYSeries());
// setChartSettings(renderer, title, xTitle, yTitle, xMin, xMax, yMin, yMax, axesColor, labelsColor)
setChartSettings(renderer, "Daily works Report", "", "Percentage", 0.5, 12.5, -100, 100, Color.GRAY, Color.LTGRAY);
renderer.setBarSpacing(0.5);
renderer.setXLabels(0);
renderer.setYLabels(10);
renderer.setXLabelsAngle(-55);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setMargins(new int[] {30, 70, 220, 10});
renderer.setYLabelsAlign(Align.RIGHT);
SimpleSeriesRenderer r = renderer.getSeriesRendererAt(0);
r.setDisplayChartValues(false); //if true: display the Y values right above the chart line
r.setChartValuesTextSize(12);
r.setChartValuesSpacing(3);
r.setGradientEnabled(true);
r.setGradientStart(-20, Color.BLUE);
r.setGradientStop(20, Color.GREEN);
if (DEBUG) Log.i(TAG, "TemperatureChart Intent execute end");
return ChartFactory.getRangeBarChartIntent(context, dataset, renderer, Type.DEFAULT, "Uptime/ Downtime");
}
}
我用作解决方案:
if(w == 1){
series.add(0, 0);
}
还有其他更好的方式