简体   繁体   English

在jfreechart条形图中设置下限/上限

[英]set lower/upper bound in jfreechart bar charts

I'm a noob with jfreechart, and I have an app that creates a simple bar chart that is working well. 我是jfreechart的新手,并且有一个应用程序可以创建运行良好的简单条形图。 The issue is, I want all the charts to show a range of 1 to 10. When the highest val in the chart is lower than that, that lower value will be the upper bound of the chart, and it will display in different increments. 问题是,我希望所有图表都显示1到10的范围。当图表中的最高val低于此值时,该下限值将成为图表的上限,并且将以不同的增量显示。 It wasn't obvious to me from the online notes where to change that.... 从网上记录中可以更改的地方,对我来说并不明显。

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) );

thanks, bp 谢谢,bp

You can change the displayed range via the axes. 您可以通过轴更改显示范围。 If i recall right, you can ask the JFreeChart instance for the XYPlot, with has a domain (x) and a range (y) axis. 如果我没记错的话,您可以向JFreeChart实例询问XYPlot,该实例具有域(x)和范围(y)轴。 Both (when instances of NumberAxis) will have a setLowerBound(double) and setUpperBound(double) method. 两者(当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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM