在 JFreeChart 中更改温度计中的水银颜色 [英] Changing mercury color in thermometer in JFreeChart
本文介绍了在 JFreeChart 中更改温度计中的水银颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 JFreeChart 创建了一个温度计图表,但我想更改温度计中的水银颜色.我怎样才能做到这一点?到目前为止,这是我的代码;请解释在哪里更改此代码:
I have created a thermometer chart with JFreeChart, but I want to change the mercury color in thermometer. How can I do this? Here is my code so far; please explain where to change this code:
final DefaultValueDataset dataset = new DefaultValueDataset(new Double(10));
// create the chart...
final ThermometerPlot plot = new ThermometerPlot(dataset);
final JFreeChart chart = new JFreeChart("Thermometer Demo 2", // chart title
JFreeChart.DEFAULT_TITLE_FONT,
plot, // plot
false); // include legend
chart.setBackgroundPaint(new Color(241,250,224));
plot.setMercuryPaint();
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setUpperBound(50);
推荐答案
您可能正在寻找 setSubrangePaint()
,如下所示.
You may be looking for setSubrangePaint()
, demonstrated below.
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.ThermometerPlot;
import org.jfree.data.general.DefaultValueDataset;
/** @see http://stackoverflow.com/questions/7597015 */
public class ThermometerDemo extends JPanel {
private static final int W = 200;
private static final int H = 2 * W;
public ThermometerDemo(double value) {
this.setLayout(new GridLayout());
DefaultValueDataset dataset = new DefaultValueDataset(value);
ThermometerPlot plot = new ThermometerPlot(dataset);
plot.setSubrangePaint(0, Color.green.darker());
plot.setSubrangePaint(1, Color.orange);
plot.setSubrangePaint(2, Color.red.darker());
JFreeChart chart = new JFreeChart("Demo",
JFreeChart.DEFAULT_TITLE_FONT, plot, true);
this.add(new ChartPanel(chart, W, H, W, H, W, H,
false, true, true, true, true, true));
}
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame("Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(1, 0));
f.add(new ThermometerDemo(40));
f.add(new ThermometerDemo(60));
f.add(new ThermometerDemo(80));
f.pack();
f.setVisible(true);
}
});
}
}
这篇关于在 JFreeChart 中更改温度计中的水银颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文