您好,您可以将默认 MercuryPaint 设置为红色并选择一个临界范围并定义正常和警告,然后删除此行:
plot.setSubrange(ThermometerPlot.CRITICAL, 70.0, 100.0);
就是这样。我做了我自己的例子,正常范围为 20-24,并且低于和高于该值。这是我的代码:
package com.tesis.ejemplo;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.ThermometerPlot;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.ApplicationFrame;
/**
* A simple demonstration application showing how to create a thermometer.
*/
public class ThermometerDemo2 extends ApplicationFrame {
/**
* Creates a new demo.
*
* @param title the frame title.
*/
private JTextField txtField = new JTextField();
private DefaultValueDataset dataset;
public ThermometerDemo2(final String title) {
super(title);
// create a dataset...
dataset = new DefaultValueDataset(new Double(24.0));
// 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
plot.setThermometerStroke(new BasicStroke(2.0f));
plot.setThermometerPaint(Color.lightGray);
plot.setRange(-10.0, 70.0);
plot.setSubrangeInfo(1, 19.0, 22.0, -10.0, 22.0);
plot.setSubrangeInfo(0, 22.0, 24.0, 10.0, 26.0);
plot.setMercuryPaint(Color.red);
plot.setSubrangePaint(1, Color.green);
// add the chart to a panel...
final ChartPanel chartPanel = new ChartPanel(chart);
setContentPane(chartPanel);
chartPanel.add( txtField );
txtField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dataset.setValue( Integer.getInteger( txtField.getText() ) );
}
});
}
public static void main(final String[] args) {
final ThermometerDemo2 demo = new ThermometerDemo2("Thermometer Demo 2");
demo.pack();
demo.setVisible(true);
}
}