Mysterious invisible chart :-9

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tedbyers
Posts: 50
Joined: Fri Oct 12, 2007 7:05 pm

Mysterious invisible chart :-9

Post by tedbyers » Fri May 16, 2008 4:51 am

I don't understand this. Similar logic does not produce the expected outcome. Here are two functions that generate charts:

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;
    }
Neither gives any exceptions.

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();
The old chart panels are simple ChartPanels, kept as private data members, so that if a new chart is requested, the old one can be explicitly removed. The image panels are just JPanels created (in NetBeans) using the visual form designer (i.e. IDE managed visual components on the form).

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

Locked