[英]set lower/upper bound in jfreechart bar charts
我是jfreechart的新手,並且有一個應用程序可以創建運行良好的簡單條形圖。 問題是,我希望所有圖表都顯示1到10的范圍。當圖表中的最高val低於此值時,該下限值將成為圖表的上限,並且將以不同的增量顯示。 從網上記錄中可以更改的地方,對我來說並不明顯。
DefaultCategoryDataset barDataSet = new DefaultCategoryDataset();
System.out.println("Setting values:");
barDataSet.setValue(rating.getFlavor(), "category", "Flavor");
barDataSet.setValue(rating.getBody(), "category", "Body");
barDataSet.setValue(rating.getAftertaste(), "category", "Aftertaste");
barDataSet.setValue(rating.getSweetness(), "category", "Sweetness");
barDataSet.setValue(rating.getFloral(), "category", "Floral");
barDataSet.setValue(rating.getSpice(), "category", "Spice");
JFreeChart chart = ChartFactory.createBarChart(null, // title
"category", // left heading
"score", // top heading
barDataSet, // dataset
PlotOrientation.HORIZONTAL,
false, // no idea what this is
true, // or this
false); // or this
System.out.println("setting bg color");
Color bgcolor = new Color(237, 232, 228);
chart.setBackgroundPaint(bgcolor);
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(new Color(112,112,112) );
謝謝,bp
您可以通過軸更改顯示范圍。 如果我沒記錯的話,您可以向JFreeChart實例詢問XYPlot,該實例具有域(x)和范圍(y)軸。 兩者(當NumberAxis的實例時)都將具有setLowerBound(double)和setUpperBound(double)方法。
chart.getXYPlot().getRangeAxis().setLowerBound(30.0);
chart.getXYPlot().getRangeAxis().setUpperBound(300.0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.