我有一个 XY 折线图,其中我不想显示零值,即使该图绘制在下面,即只是忽略零值,如在堆积条形图中效果很好。
更新:让我详细告诉你。这是我必须绘制的数据,其中我有两个不应该显示但绘制的零值。
我在条形图中找到了一种方法-setignoreZeroValues()
忽略条形图中的零。
double data1[] = {0.0, 33.0, 44.0, 11.0, 77.0, 44.0,
55.0, 66.0, 27.0, 99.0, 122.0, 0.0};
XYSeries series1 = new XYSeries("Last year", false);
for (int i = 0; i < data1.length; i++) {
series1.add(data1[i], i);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
JFreeChart chart = ChartFactory.createXYLineChart("Title", "Values",
"", dataset, PlotOrientation.HORIZONTAL, true, true, false);
chart.setBackgroundPaint(Color.LIGHT_GRAY);
XYPlot plot = (XYPlot) chart.getPlot();
String[] Cat = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"};
SymbolAxis rangeAxis = new SymbolAxis("Cat", Cat);
//rangeAxis.setTickUnit(new NumberTickUnit(1));
//rangeAxis.setRange(0,grade.length);
plot.setRangeAxis(rangeAxis);