问题
I want to combine 3 bar series and 3 line series in one chart using achartengine.
When I specify the type of chart as BarChart and give it 3 series, things work right. The bars widths are what I set and the spacing and colouring is correct: (see image here: http://i42.tinypic.com/ifu1ap.jpg)
But when I specify the chart type as
mChart = ChartFactory.getCombinedXYChartView(getView().getContext(), mDataset, mRenderer, new String[] {BarChart.TYPE, BarChart.TYPE, BarChart.TYPE, LineChart.TYPE, LineChart.TYPE,LineChart.TYPE });
the bars display on top of each other and the widths aren't right: (see image here: http://i43.tinypic.com/2vum2xv.jpg)
Neither XYMultipleSeriesRenderer.setBarWidth()
nor XYSeriesRenderer.setLineWidth()
works for the bar widths.
I thought that if I added the XYSeries x values with an offset that I could fix the overlapping bars issue but then the widths of the bars are still not what I set it to be.
Does anyone know (the right way) how to make a chart that shows multiple bar and line series in one chart?
回答1:
You are correct about using an offset to render the bars such as they don't overlap.
However, for spacing them, you need to use renderer.setBarSpacing(2);
which means that the space between 2 items in the same series is equal to two times width of one bar.
来源:https://stackoverflow.com/questions/20195585/multiple-bars-and-lines-in-achartengine