java - JFreeChart BarChart -> 无渐变

标签 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

谢谢

最佳答案

问题在于您正在使用的 BarPainter。 JFreeChart 1.0.13 版默认使用GradientBarPainter,它为条形添加了金属感的外观。如果您想要“旧”外观,解决方案是使用 StandardBarPainter

final CategoryPlot plot = chart.getCategoryPlot();
((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter());

应该可以的。

或者,如果你想使用 JFreeChart 的 BarRenderer,你可以通过调用静态方法 setDefaultBarPainter() 来强制它使用 StandardBarPainter初始化你的渲染器。

final CategoryPlot plot = chart.getCategoryPlot();
BarRenderer.setDefaultBarPainter(new StandardBarPainter());
((BarRenderer) plot.getRenderer()).setBarPainter(new BarPainter());

如果您想要更多地控制图表,您总是可以从头开始构建它,而不是使用 ChartFactory,但这确实需要很多额外的代码。

关于java - JFreeChart BarChart -> 无渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7076305/

相关文章:

css - 在纸质菜单 Polymer 1.0 中使用不同的颜色

java - 如何在 JFreeChart 中旋转数 Axis 域上的刻度标记标签?

java - 为什么 Quartz Scheduler 在 x 分钟后停止在 Heroku 上工作?

java - Eclipse 导出可运行的 jar,其中主类位于库 jar 中

javax.net.ssl.SSLHandshakeException : sun. security.validator.ValidatorException : PKIX path building failed happens on one machine, 但不是另一个

java - 获取绘图中的最小可见值

java - 如何使用 JFreeChart 在折线图中绘制多条线?

java - 客户端和服务器之间使用套接字进行通信

python - 如何将所有黑色像素更改为白色(OpenCV)?

java - 将位图 RGB 像素加载到 BufferedImage 中