こんにちは。デフォルトの MercuryPaint を赤に設定し、重要な範囲を 1 つだけ選択して通常と警告を定義し、次の行を削除します。
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);
}
}