sho*_*rty 25 java colors jfreechart bar-chart
默认情况下,我的条形图始终使用渐变颜色绘制.我只想要一个没有任何风格效果的简单颜色.
有人可以帮忙吗?
码:
final JFreeChart chart = ChartFactory.createBarChart(
"", // chart title
xLabel, // domain axis label
yLabel, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
false, // tooltips?
false // URLs?
);
final CategoryPlot plot = chart.getCategoryPlot();
// SOMETHING HAS TO BE DONE HERE
showChart(chart); // Simply shows the chart in a new window
Run Code Online (Sandbox Code Playgroud)
谢谢
Jes*_*Jes 44
问题在于BarPainter你正在使用.JFreeChart版本1.0.13默认使用GradientBarPainter,它为条形添加了金属外观.如果你想要"旧"看起来解决方案是使用StandardBarPainter.
final CategoryPlot plot = chart.getCategoryPlot();
((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter());
Run Code Online (Sandbox Code Playgroud)
应该这样做.
或者,如果您想使用JFreeChart BarRenderer,则可以在初始化渲染器之前强制它StandardBarPainter通过调用静态方法来使用它setDefaultBarPainter().
final CategoryPlot plot = chart.getCategoryPlot();
BarRenderer.setDefaultBarPainter(new StandardBarPainter());
((BarRenderer) plot.getRenderer()).setBarPainter(new BarPainter());
Run Code Online (Sandbox Code Playgroud)
如果你想要更多地控制图表,你总是可以从头开始构建它而不是使用它ChartFactory,但这确实需要很多额外的代码.
小智 7
在ChartFactory中创建图表之前,您可以设置图表主题:
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
Run Code Online (Sandbox Code Playgroud)
默认值是添加渐变的JFreeTheme.可以使用以下主题:
ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());
Run Code Online (Sandbox Code Playgroud)