1
我正在使用achartengine jar進行條形圖視圖。我的條形圖設計示例圖要求如下。如何在條形圖上繪製軸之間的虛線android
- 將頂部圖像我requiremnt條形圖
- 底部圖片是我的輸出圖像。
我的代碼是:
public class TestClass extends AppCompatActivity {
private GraphicalView BarChartView;
@SuppressLint("ParserError")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
if (BarChartView==null)
{
XYMultipleSeriesRenderer renderer = buildBarRenderer();
setChartSettings(renderer);
BarChartView = ChartFactory.getBarChartView(this, getBarDataset(), renderer, Type.DEFAULT);
LinearLayout playout = (LinearLayout) findViewById(R.id.graph2);
playout.addView(BarChartView);
} else
{
BarChartView.repaint();
BarChartView.setVisibility(View.GONE);
}
}
private void setChartSettings(XYMultipleSeriesRenderer renderer)
{
renderer.setYTitle("Hits");
renderer.setXAxisMin(0);
renderer.setXAxisMax(7);
renderer.setYAxisMin(0);
renderer.setYAxisMax(100);
}
private XYMultipleSeriesDataset getBarDataset()
{
XYSeries series1 = new XYSeries("A");
XYSeries series2 = new XYSeries("B");
XYSeries series3 = new XYSeries("C");
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
series1.add(3, 50);
dataset.addSeries(series1);
series2.add(4, 25);
dataset.addSeries(series2);
series3.add(5, 100);
dataset.addSeries(series3);
return dataset;
}
protected XYMultipleSeriesRenderer buildBarRenderer() {
XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
//double[] range = {5,5,0};
mrenderer.setAxisTitleTextSize(16);
mrenderer.setChartTitleTextSize(20);
mrenderer.setLabelsTextSize(15);
mrenderer.setLegendTextSize(15);
mrenderer.setBarSpacing(0.5);
mrenderer.setXLabels(0);
mrenderer.addXTextLabel(0, "SAVINGS TOTAL");
mrenderer.addXTextLabel(1.5, "SPEND BREAKDOWN");
mrenderer.addXTextLabel(3, "DEPT");
mrenderer.setMargins(new int[]{20, 30, 15, 0});
mrenderer.setAxesColor(Color.WHITE);
mrenderer.setChartTitle("");
mrenderer.setXTitle("");
// mrenderer.setInitialRange(range, 1);
mrenderer.setBarWidth(100);
XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setColor(Color.GREEN);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.RED);
XYSeriesRenderer renderer3 = new XYSeriesRenderer();
renderer3.setColor(Color.BLUE);
mrenderer.addSeriesRenderer(renderer1);
mrenderer.addSeriesRenderer(renderer2);
mrenderer.addSeriesRenderer(renderer3);
return mrenderer;
}
}
請請幫我解決吧Grapg點綴X和Y軸之間的線。 如果有人有想法,請告訴我。提前致謝。
感謝您的回覆Harin ..它不工作harin..could請你告訴我,我應該在哪裏我的代碼中添加此行程。 @Harin Kaklotar – karthik
下面的代碼對我來說工作得很好。 renderer.setShowGrid(true); renderer.setShowCustomTextGrid(true); – karthik