我在android中制作了条形图。条形图中的正值已被修正,并且值太负。绘制图表中的正值是正确的但负值不是绘制或不填充颜色。我不知道如何绘制负值的条形图。任何人都可以帮助我。
String[] titles = new String[] { "USER INPUTS" };
List<double[]> x = new ArrayList<double[]>();
x.add(new double[] { 1, 2, 3, 4, 5 });
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 2, -3, 4, 3, -7 });
dataset = new XYMultipleSeriesDataset();
renderer = new XYMultipleSeriesRenderer();
renderer.setChartTitle("USER INPUTS");
renderer.setXTitle("X");
renderer.setYTitle("Y");
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setXAxisMin(0);
renderer.setXAxisMax(10);
renderer.setYAxisMin(-40);
renderer.setYAxisMax(40);
renderer.setClickEnabled(false);
renderer.setExternalZoomEnabled(false);
renderer.setZoomButtonsVisible(true);
renderer.setPanLimits(new double[] { 0, 5, 0, 100 });
renderer.setZoomLimits(new double[] { 10, 20, 10, 40 });
renderer.setShowGrid(true);
renderer.setPanEnabled(false, false);
renderer.setZoomEnabled(false, false);
renderer.setBarSpacing(1.5);
renderer.setLabelsColor(Color.BLUE);
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] { 20, 30, 15, 20 });
renderer.setBackgroundColor(Color.GREEN);
renderer.setMarginsColor(getResources().getColor(R.color.transparent));
rendererSeries = new XYSeriesRenderer();
rendererSeries.setColor(Color.GREEN);
rendererSeries.setDisplayChartValues(true);
renderer.addSeriesRenderer(rendererSeries);
if (mChartView == null) {
Log.d("Oncreate ", "if (mChartView == null)");
mChartView = ChartFactory.getBarChartView(context,
mDataset(titles, x, values), renderer, Type.DEFAULT);
layoutBarGraph.addView(mChartView, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
} else {
// mChartView.repaint();
Log.d("Oncreate ", "if (mChartView != null)");
}
答案 0 :(得分:2)
也许已经晚了但我希望它有所帮助。
您必须将YAxis属性startAtZero设置为false。
请参阅以下代码:
//For me, AxisDependency.LEFT because I was using an horizontar-bar
YAxis yAxis = mChart.getAxis(YAxis.AxisDependency.LEFT);
yAxis.setStartAtZero(false);