Code: Select all
private static JFreeChart createChart(String lbl, double lb, double ub, double value) {
DefaultValueDataset dataset = new DefaultValueDataset(value);
ThermometerPlot plot = new ThermometerPlot(dataset);
plot.setBulbRadius(plot.getColumnRadius());
plot.setLowerBound(lb);
plot.setUpperBound(ub);
plot.setUnits(ThermometerPlot.UNITS_NONE);
JFreeChart chart = new JFreeChart(lbl, plot);
chart.setBackgroundPaint(java.awt.Color.white);
return chart;
}
private static JFreeChart creatDialChart(String lbl, double lb, double ub, double value) {
JFreeChart chart = null;
DefaultValueDataset dataset = new DefaultValueDataset(value);
MeterPlot plot = new MeterPlot(dataset);
plot.setRange(new Range(lb, ub));
plot.setNeedlePaint(java.awt.Color.darkGray);
plot.setDialBackgroundPaint(java.awt.Color.white);
plot.setDialOutlinePaint(java.awt.Color.gray);
plot.setDialShape(DialShape.CHORD);
plot.setMeterAngle(260);
plot.setTickLabelsVisible(true);
plot.setTickLabelFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
plot.setTickLabelPaint(java.awt.Color.darkGray);
plot.setTickSize(5.0);
plot.setTickPaint(java.awt.Color.lightGray);
plot.setValuePaint(java.awt.Color.black);
plot.setValueFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 14));
chart = new JFreeChart(lbl,JFreeChart.DEFAULT_TITLE_FONT, plot, true);
return chart;
}
And here is how they're used:
Code: Select all
org.jfree.chart.ChartPanel aChartPanel = new org.jfree.chart.ChartPanel(createChart(cTitle,lb,ub/rf,v));
aChartPanel.setSize(imagePanel2.getSize());
if (oldChartPanel2 != null) {
imagePanel2.remove(oldChartPanel2);
}
oldChartPanel2 = aChartPanel;
imagePanel2.add(aChartPanel);
imagePanel2.validate();
aChartPanel = new org.jfree.chart.ChartPanel(creatDialChart(cTitle,lb,ub/rf,v));
if (oldChartPanel3 != null) {
imagePanel3.remove(oldChartPanel3);
}
oldChartPanel3 = aChartPanel;
imagePanel3.add(aChartPanel);
imagePanel3.validate();
this.validate();
None of this code gives any exceptions or other errors. No null pointers.
The mystery is that the thermometer chart displays just fine. The meter plot NEVER appears.
What have I overlooked WRT the meter plot?
On a completely different matter, is it possible to tell the thermometer plot to display itself horizontally?
Thanks
Ted