-1
我需要在圖表中設置最小X-tick間隔。我有一個包含1000個條目的數據集,即<0,12>,<5,22>,<10,23>,...,<1000,20>
。在數據集,X值之間的間隔是等於5。在我想設置X-蜱間隔等於100JFreeChart:在圖表中設置最小X-tick間隔
我使用此代碼圖表,但它不工作:
NumberAxis range = (NumberAxis)plot.getRangeAxis();
range.setTickUnit(new NumberTickUnit(100));
這裏是我的代碼片段:
private JFreeChart createChart(CategoryDataset dataset)
{
final JFreeChart chart = ChartFactory.createAreaChart(
this.title,
"Time",
"Net demand",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
Title t = new TextTitle(this.subtitle);
chart.addSubtitle(t);
int transparency = 95;
Color c = new Color(1, 158, 115, transparency);
final CategoryPlot plot = chart.getCategoryPlot();
CategoryItemRenderer renderer = new CustomRenderer(c);
renderer.setSeriesOutlinePaint(0, Color.black);
renderer.setSeriesOutlineStroke(0, new BasicStroke(0.5f));
renderer.setSeriesPaint(0,c);
plot.setRenderer(renderer);
NumberAxis range = (NumberAxis)plot.getRangeAxis();
range.setTickUnit(new NumberTickUnit(60));
return chart;
}
謝謝。在這種情況下,我收到編譯錯誤:無法從CategoryAxis投射到NumberAxis –
是否需要在NumberAxis中重寫refreshTicks()? –
不,我沒有注意到你正在使用CategoryPlot,我認爲它是一個XYPlot。由於您的x值是數字,您應該嘗試使用XYAreaChart。 –