android中表格绘图

android中表格绘图
 public class AverageTemperatureChart extends AbstractDemoChart {

public String getName() {
return "Average temperature";
}

public String getDesc() {
return "The average temperature in 4 Greek islands (line chart)";
}

/**
 * Executes the chart demo.
 * 
 * @param context
 *            the context
 * @return the built intent
 */
public Intent execute(Context context) {
// 每个item的title
String[] titles = new String[] { "Crete", "Corfu", "Thassos",
"Skiathos" };
// x轴的值
List x = new ArrayList();
for (int i = 0; i < titles.length; i++) {
x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
}
// y轴的值
List values = new ArrayList();
values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4,
26.1, 23.6, 20.3, 17.2, 13.9 });
values.add(new double[] { 10, 10, 12, 15, 20, 24, 26, 26, 23, 18, 14,
11 });
values.add(new double[] { 5, 5.3, 8, 12, 17, 22, 24.2, 24, 19, 15, 9, 6 });
values.add(new double[] { 9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10 });
int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.CYAN,
Color.YELLOW };
// 点的样式
PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE,
PointStyle.DIAMOND, PointStyle.TRIANGLE, PointStyle.SQUARE };
XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
int length = renderer.getSeriesRendererCount();
// 点是空心还是实心
for (int i = 0; i < length; i++) {
((XYSeriesRenderer) renderer.getSeriesRendererAt(i))
.setFillPoints(true);
}

// 图表部分的背景颜色
renderer.setBackgroundColor(Color.parseColor("#f3f3f3"));
renderer.setApplyBackgroundColor(true);
// 图表与屏幕四边的间距颜色
renderer.setMarginsColor(Color.argb(0, 0xF3, 0xF3, 0xF3));
renderer.setChartTitleTextSize(30);
renderer.setAxisTitleTextSize(25);
// renderer.setLegendHeight(50);
// 图例文字的大小
renderer.setLegendTextSize(20);
renderer.setMargins(new int[] { 50, 50, 50, 30 });
// x、y轴上刻度颜色
renderer.setXLabelsColor(Color.BLACK);
renderer.setYLabelsColor(0, Color.BLACK);

// 最后两个参数代表轴的颜色和轴标签的颜色
setChartSettings(renderer, "Average temperature", "Month",
"Temperature", 0.5, 12.5, -10, 40, Color.BLACK, Color.BLACK);
// 轴上数字的数量
renderer.setXLabels(12);
renderer.setYLabels(10);
// 是否显示网格
renderer.setShowGrid(true);
// x或y轴上数字的方向,相反的。
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
// 有问题的方法
// renderer.setZoomButtonsVisible(true);
// renderer.setPanLimits(new double[] { -10, 20, -10, 40 });
// renderer.setZoomLimits(new double[] { -10, 20, -10, 40 });

Intent intent = ChartFactory.getLineChartIntent(context,
buildDataset(titles, x, values), renderer,
"Average temperature");
return intent;
}
}

你可能感兴趣的:(android中表格绘图)