我已经从其网站上给出了几个关于android绘图示例的更改。但我仍然无法使条形图变得与下图相似:
有没有人清楚地知道我忘了哪一部分?
这是我的代码:
private void prepareSuccessRate() {
// initialize our XYPlot reference:
plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
formatter3 = new MyBarFormatter(Color.argb(200, 100, 100, 150),
Color.LTGRAY);
formatter2 = new MyBarFormatter(Color.argb(200, 50, 100, 100),
Color.YELLOW);
// add a dark, semi-transparent background to the selection label
// widget:
Paint p = new Paint();
p.setARGB(100, 0, 0, 0);
// reduce the number of range labels
plot.setRangeLowerBoundary(0, BoundaryMode.FIXED);
plot.getGraphWidget().setGridPadding(0, 10, 0, 0);
plot.setTicksPerRangeLabel(1);
plot.setTicksPerDomainLabel(1);
// setup check box listers:
series1CheckBox = (CheckBox) findViewById(R.id.s1CheckBox);
series2CheckBox = (CheckBox) findViewById(R.id.s2CheckBox);
// obtaining file calculating variables
TransfObject.prepareData();
if (TransfObject.manyXP() != 0) {
// display it on UI
ToastObject.postFastMessage("ada "+TransfObject.TotalFailedXP());
// success & failure data
series1Numbers = getSingleValueNumber(TransfObject.TotalSuccessXP());
series1aNumbers = getSingleValueNumber(TransfObject.TotalFailedXP());
series1 = new SimpleXYSeries(Arrays.asList(series1Numbers),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, sTitleSuccess);
series2 = new SimpleXYSeries(Arrays.asList(series1aNumbers),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, sTitleFailed);
series2Numbers = getManyOrderedExp(1);
// max y-value
plot.setRangeTopMax(TransfObject.manyXP());
plot.setRangeBottomMax(3);
plot.setDomainValueFormat(new GraphXLabelFormat());
updatePlot();
}
plot.setRangeLabel(sTitleNumberOfExp);
plot.setTitle("Success Rate");
plot.setDomainLabel(sDomainLabel);
}
private void updatePlot() {
// Remove all current series from each plot
Iterator<XYSeries> iterator1 = plot.getSeriesSet().iterator();
while (iterator1.hasNext()) {
XYSeries setElement = iterator1.next();
plot.removeSeries(setElement);
}
if (repType == Stats.BY_SUCCESS_RATE) {
// displaying success rate
// color
plot.addSeries(series1, formatter3);
plot.addSeries(series2, formatter2);
} else if (repType == Stats.BY_TRANSFER_SPEED) {
// displaying transfer speed
// color
plot.addSeries(series1, formatter2);
} else if (repType == Stats.BY_TRANSFER_TIME) {
// displaying transfer time
// color
plot.addSeries(series1, formatter1);
}
MyBarRenderer renderer = ((MyBarRenderer) plot
.getRenderer(MyBarRenderer.class));
renderer.setBarRenderStyle((BarRenderer.BarRenderStyle) BarRenderer.BarRenderStyle.SIDE_BY_SIDE);
renderer.setBarWidthStyle((BarRenderer.BarWidthStyle) BarRenderer.BarWidthStyle.FIXED_WIDTH);
renderer.setBarWidth(50);
plot.redraw();
}