本文介绍了JFreeChart BarChart - > NO梯度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的条形图总是默认使用渐变颜色绘制。



任何人都可以帮忙?



代码:

  final JFreeChart chart = ChartFactory.createBarChart(
,//图表标题
xLabel,//域轴标签
yLabel,//范围轴标签
数据集//数据
PlotOrientation.VERTICAL //方向
true,// include legend
false,// tooltips?
false // URLs?
);

final CategoryPlot plot = chart.getCategoryPlot();
// SOMETHING已经完成这里

showChart(chart); //只需在新窗口中显示图表

感谢

BarPainter 中。 JFreeChart版本1.0.13默认是使用 GradientBarPainter ,它为条形添加了一个金属色的外观。如果你想要旧的外观,解决方案是使用 StandardBarPainter

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

应该这样做。



,如果你想使用JFreeChart的 BarRenderer ,你可以通过调用静态方法强制使用 StandardBarPainter $ c> setDefaultBarPainter()。

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

如果你想更多地控制图表,你总是可以从头开始构建, code> ChartFactory ,但这需要很多额外的代码。


my bar chart is always drawn with a gradient color by default. I just want a simple color without any styled effects.

Can anyone help ?

Code:

   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

Thanks

解决方案

The problem lies in the BarPainter you are using. The JFreeChart version 1.0.13 default is to use GradientBarPainter which adds a metallic-ish look to the bar. If you want the "old" look the solution is to use the StandardBarPainter.

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

That should do it.

Alternatively, if you want use JFreeChart's BarRenderer, you could force it to use the StandardBarPainter by calling the static method setDefaultBarPainter() before initializing your renderer.

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

If you want more control of the chart you can always build it from the ground up instead of using ChartFactory, but that does require a lot extra code.

这篇关于JFreeChart BarChart - > NO梯度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 04:05