Strange graphical problem while drawing a chart.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Fithvael
Posts: 1
Joined: Mon Oct 11, 2010 12:04 pm
antibot: No, of course not.

Strange graphical problem while drawing a chart.

Post by Fithvael » Mon Oct 11, 2010 12:31 pm

Greetings, friends.
I've been using JFreeChart for a few days and I'm really satisfied with this tool. However, I've encountered quite an irritating problem and I would really appreciate it, if You could help me resolve this...

Code: Select all

package Sygnaly;

import Funkcje.SygnalSinusoidalnyWzor;
import javax.swing.GroupLayout;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeriesCollection;

public class SygnalSinusoidalny {

    JPanel card = new JPanel();
    double A;
    double T;
    double t1;
    double d;
    ChartPanel chartPanel;
    XYSeriesCollection xyDataset = new XYSeriesCollection();

    public SygnalSinusoidalny() {
        SpinnerNumberModel modelA = new SpinnerNumberModel(50.0, 0.0, 100.0, 1.0);
        final JSpinner Amplituda = new JSpinner(modelA);
        A = (Double) Amplituda.getValue();
        ChangeListener listenerA = new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                setA((double) (Double) Amplituda.getValue());
                System.out.println(getA());
                SygnalSinusoidalnyWzor sinus = new SygnalSinusoidalnyWzor(getA(), getT(), getT1(), getD());
                getXyDataset().removeAllSeries();
                getXyDataset().addSeries(sinus.zwrocSerie());
                getChartPanel().repaint();
            }
        };
        Amplituda.addChangeListener(listenerA);

        SpinnerNumberModel modelT = new SpinnerNumberModel(50.0, 0.0, 100.0, 1.0);
        final JSpinner Okres = new JSpinner(modelT);
        T = (Double) Okres.getValue();
        ChangeListener listenerT = new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                setT((double) (Double) Okres.getValue());
                System.out.println(getT());
                SygnalSinusoidalnyWzor sinus = new SygnalSinusoidalnyWzor(getA(), getT(), getT1(), getD());
                getXyDataset().removeAllSeries();
                getXyDataset().addSeries(sinus.zwrocSerie());
                getChartPanel().repaint();
            }
        };
        Okres.addChangeListener(listenerT);

        SpinnerNumberModel modelt1 = new SpinnerNumberModel(0.0, 0.0, 100.0, 1.0);
        final JSpinner CzasPoczatkowy = new JSpinner(modelt1);
        t1 = (Double) CzasPoczatkowy.getValue();
        ChangeListener listenert1 = new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                setT1((double) (Double) CzasPoczatkowy.getValue());
                System.out.println(getT1());
                SygnalSinusoidalnyWzor sinus = new SygnalSinusoidalnyWzor(getA(), getT(), getT1(), getD());
                getXyDataset().removeAllSeries();
                getXyDataset().addSeries(sinus.zwrocSerie());
                getChartPanel().repaint();
            }
        };
        CzasPoczatkowy.addChangeListener(listenert1);

        SpinnerNumberModel modeld = new SpinnerNumberModel(50.0, 0.0, 100.0, 1.0);
        final JSpinner CzasTrwania = new JSpinner(modeld);
        d = (Double) CzasTrwania.getValue();
        ChangeListener listenerd = new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                setD((double) (Double) CzasTrwania.getValue());
                System.out.println(getD());
                SygnalSinusoidalnyWzor sinus = new SygnalSinusoidalnyWzor(getA(), getT(), getT1(), getD());
                getXyDataset().removeAllSeries();
                getXyDataset().addSeries(sinus.zwrocSerie());
                getChartPanel().repaint();
            }
        };
        CzasTrwania.addChangeListener(listenerd);

        SygnalSinusoidalnyWzor sinus = new SygnalSinusoidalnyWzor(getA(), getT(), getT1(), getD());
        xyDataset.addSeries(sinus.zwrocSerie());

        JFreeChart chart = ChartFactory.createXYLineChart("Sygnał sinusoidalny", "X", "Y",
                xyDataset, PlotOrientation.VERTICAL, true, true, false);

        chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        GroupLayout layout = new GroupLayout(getCard());
        getCard().setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        layout.setHorizontalGroup(
                layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(chartPanel).addGroup(layout.createSequentialGroup().addComponent(Amplituda).addComponent(Okres).addComponent(CzasPoczatkowy).addComponent(CzasTrwania))));
        layout.setVerticalGroup(
                layout.createSequentialGroup().addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(Amplituda).addComponent(Okres).addComponent(CzasPoczatkowy).addComponent(CzasTrwania)).addComponent(chartPanel));

    }

    public JPanel getCard() {
        return card;
    }

    /**
     * @return the A
     */
    public double getA() {
        return A;
    }

    /**
     * @param A the A to set
     */
    public void setA(double A) {
        this.A = A;
    }

    /**
     * @return the T
     */
    public double getT() {
        return T;
    }

    /**
     * @param T the T to set
     */
    public void setT(double T) {
        this.T = T;
    }

    /**
     * @return the t1
     */
    public double getT1() {
        return t1;
    }

    /**
     * @param t1 the t1 to set
     */
    public void setT1(double t1) {
        this.t1 = t1;
    }

    /**
     * @return the d
     */
    public double getD() {
        return d;
    }

    /**
     * @param d the d to set
     */
    public void setD(double d) {
        this.d = d;
    }

    /**
     * @return the chartPanel
     */
    public ChartPanel getChartPanel() {
        return chartPanel;
    }

    /**
     * @param chartPanel the chartPanel to set
     */
    public void setChartPanel(ChartPanel chartPanel) {
        this.chartPanel = chartPanel;
    }

    /**
     * @return the xyDataset
     */
    public XYSeriesCollection getXyDataset() {
        return xyDataset;
    }

    /**
     * @param xyDataset the xyDataset to set
     */
    public void setXyDataset(XYSeriesCollection xyDataset) {
        this.xyDataset = xyDataset;
    }


}
Short description:
This is a part of a program, which (future) aim is to display various signals. I'm using the card layout manager in order to create an individual card for each signal. In the code above, You can see the class, that aims to create the card for the sinus signal and return the card to the main class.
The
"SygnalSinusoidalnyWzor sinus = new SygnalSinusoidalnyWzor(getA(), getT(), getT1(), getD());"
line creates the object, that calculates the signal and creates the whole dataset by the usage of the "sinus.zwrocSerie()" method. As You can see, there are also various spinners defined in the code - they aim to provide the parameters for the signal.

Now, about the problem...
Everything seems to work correctly,
Image

...but as I spin through the values in the spinners, sometimes i get the following screen:
Image

It seems to be some refreshing problem, as I've noticed, that after "hiding" (e.g. minimizing and maximizing) the window, the strange part of the chart in the left upper corner disappears. I've also noticed, that the memory usage of the application steadily grows as I spin through the values - so maybe that's also some kind of hint?

I would truly appreciate any help, that You could provide on this matter, and... Sorry for the mistakes, english is not my mother language.

Locked