Hello David
I am trying to plot a CombinedPlot of two TimeSeries Plots both of which are updated by two threads( or perhaps updated by mouse clicks ).
But while my chart's X-axis moves,the plots are not being shown as plotted( i:e there is no red line graph being generated).Moreover, after some time the X-AXIS'S leftmost point remains static while the rightmost points keep huddling together. The statement
System.out.println("Now = "+now.toString());
does show the output at Dos Window though.
could you please guide me regarding this as this is very very urgent.
N.B: What is a crossHair?
import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.event.*;
import com.jrefinery.data.BasicTimeSeries;
import com.jrefinery.data.TimeSeriesCollection;
import com.jrefinery.data.Millisecond;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.chart.combination.*;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ValueAxis;
import com.jrefinery.chart.JFreeChartPanel;
import com.jrefinery.chart.*;
import com.jrefinery.data.*;
import com.jrefinery.date.*;
import com.jrefinery.chart.data.*;
class SessionLogger implements Runnable {
public void run(){
while(true){
try{
Thread.sleep(500);
}
catch(Exception e){}
}
}//end run
}//end SessionLogger
class ResponseLogger implements Runnable {
public void run(){
while(true){
try{
Thread.sleep(500);
}
catch(Exception e){}
}
}//end run
}//end ResponseLogger
public class LineLogger extends ApplicationFrame implements ActionListener
{
CombinedChart chartToCombine;
JFreeChart chart=null;
TimeSeriesCollection dataset;
BasicTimeSeries series;
protected double lastValue = 100.0;
public LineLogger()
{
series = new BasicTimeSeries("Random Data", Millisecond.class);
dataset = new TimeSeriesCollection(series);
ValueAxis timeAxis=new HorizontalDateAxis("domain");
timeAxis.setAutoRange(true);
timeAxis.setFixedAutoRange(60000.0);
NumberAxis[] valueAxis = new NumberAxis[2];
for (int i=0; i<valueAxis.length; i++) {
valueAxis = new VerticalNumberAxis();
valueAxis.setAutoRangeIncludesZero(false);
valueAxis.setCrosshairVisible(false);
}
CombinedPlot combinedPlot=new CombinedPlot(timeAxis,CombinedPlot.VERTICAL);
chartToCombine=ChartFactory.createCombinableTimeSeriesChart(timeAxis,valueAxis[0],dataset);
combinedPlot.add(chartToCombine);
chartToCombine=ChartFactory.createCombinableTimeSeriesChart(timeAxis,valueAxis[1],dataset);
combinedPlot.add(chartToCombine);
combinedPlot.adjustPlots();
chart=new JFreeChart(dataset,combinedPlot,"LINELOGGER",JFreeChart.DEFAULT_TITLE_FONT,true);
JPanel content = new JPanel(new BorderLayout());
JButton button = new JButton("Add New Data Item");
button.setActionCommand("ADD_DATA");
button.addActionListener(this);
JFreeChartPanel chartPanel = new JFreeChartPanel(chart);
content.add(chartPanel);
content.add(button,BorderLayout.SOUTH);
this.setContentPane(content);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("ADD_DATA")) {
double factor = 0.9 + 0.2*Math.random();
this.lastValue = lastValue*factor;
Millisecond now = new Millisecond();
System.out.println("Now = "+now.toString());
this.series.add(new Millisecond(), lastValue);
}
}
public static void main(String args[])
{
LineLogger linelogger=new LineLogger();
linelogger.pack();
linelogger.setVisible(true);
Thread t1=new Thread(new SessionLogger());
Thread t2=new Thread(new ResponseLogger());
t1.setDaemon(false);
t2.setDaemon(false);
t1.start();
t2.start();
}
}//end LineLogger
Problems !! Urgent help required!
Re: Problems !! Urgent help required!
Is it because i haven't used CombinedDataset?
If so, could you help me as to how to use it?
Thanks in advance
Gaurav Kathotia
If so, could you help me as to how to use it?
Thanks in advance
Gaurav Kathotia
Re: Problems !! Urgent help required!
There is an example in the JFreeChartDemo, in the displayOverlaidChart() method for instance
Re: Problems !! Urgent help required!
Hello
I am still not getting any visible plot. There is only a moving x-axis , that too stops moving from the left side after some time.
Is there any other way to implement the DynamicDataDemo on
a combined plot of two time series charts updated by either threads or
mouse clicks?
This is required urgently , so any help will be greatly appreciated.
Gaurav Kathotia
I am still not getting any visible plot. There is only a moving x-axis , that too stops moving from the left side after some time.
Is there any other way to implement the DynamicDataDemo on
a combined plot of two time series charts updated by either threads or
mouse clicks?
This is required urgently , so any help will be greatly appreciated.
Gaurav Kathotia
Re: Problems !! Urgent help required!
Hello,
I have the same problem! I constructed a vertically combined graph consisting of 2 dynamic TimeSeriesCharts. Initially my dataset contains one value. Each 10 seconds this dataset is updated.
I only see a moving x axis, the y axis' range goes from 0 to 1 and I see no data at all.
Does somebody had a solution for this problem? Is it a bug or am I doing something wrong? It is quite urgent...
Thanx
Isabelle
(PIDDataset extends AbstractSeriesDataset implements XYDataset...)
private JFreeChartPanel getChartPanel(PIDDataset dataset) {
SubSeriesDataset instant = new SubSeriesDataset(dataset, 0);
SubSeriesDataset predicted = new SubSeriesDataset(dataset, 1);
SubSeriesDataset pOut = new SubSeriesDataset(dataset, 2);
SubSeriesDataset pIn = new SubSeriesDataset(dataset, 3);
SubSeriesDataset energy = new SubSeriesDataset(dataset, 4);
ValueAxis xAxis = new HorizontalDateAxis("Time");
xAxis.setTickMarksVisible(true);
xAxis.setCrosshairVisible(false);
NumberAxis yAxis1 = new VerticalNumberAxis("kW");
yAxis1.setCrosshairVisible(false);
NumberAxis yAxis2 = new VerticalNumberAxis("kWh");
yAxis2.setCrosshairVisible(false);
CombinedDataset data1 = new CombinedDataset(new SeriesDataset[] {instant, predicted, pOut, pIn} );
CombinedDataset data2 = new CombinedDataset(new SeriesDataset[] {energy} );
CombinedPlot combinedPlot = new CombinedPlot(xAxis, CombinedPlot.VERTICAL);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis1, data1), 1);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis2, data2), 1);
combinedPlot.adjustPlots();
JFreeChart chart = new JFreeChart(dataset, combinedPlot, "PID", JFreeChart.DEFAULT_TITLE_FONT, true);
return new JFreeChartPanel(chart);
}
I have the same problem! I constructed a vertically combined graph consisting of 2 dynamic TimeSeriesCharts. Initially my dataset contains one value. Each 10 seconds this dataset is updated.
I only see a moving x axis, the y axis' range goes from 0 to 1 and I see no data at all.
Does somebody had a solution for this problem? Is it a bug or am I doing something wrong? It is quite urgent...
Thanx
Isabelle
(PIDDataset extends AbstractSeriesDataset implements XYDataset...)
private JFreeChartPanel getChartPanel(PIDDataset dataset) {
SubSeriesDataset instant = new SubSeriesDataset(dataset, 0);
SubSeriesDataset predicted = new SubSeriesDataset(dataset, 1);
SubSeriesDataset pOut = new SubSeriesDataset(dataset, 2);
SubSeriesDataset pIn = new SubSeriesDataset(dataset, 3);
SubSeriesDataset energy = new SubSeriesDataset(dataset, 4);
ValueAxis xAxis = new HorizontalDateAxis("Time");
xAxis.setTickMarksVisible(true);
xAxis.setCrosshairVisible(false);
NumberAxis yAxis1 = new VerticalNumberAxis("kW");
yAxis1.setCrosshairVisible(false);
NumberAxis yAxis2 = new VerticalNumberAxis("kWh");
yAxis2.setCrosshairVisible(false);
CombinedDataset data1 = new CombinedDataset(new SeriesDataset[] {instant, predicted, pOut, pIn} );
CombinedDataset data2 = new CombinedDataset(new SeriesDataset[] {energy} );
CombinedPlot combinedPlot = new CombinedPlot(xAxis, CombinedPlot.VERTICAL);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis1, data1), 1);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis2, data2), 1);
combinedPlot.adjustPlots();
JFreeChart chart = new JFreeChart(dataset, combinedPlot, "PID", JFreeChart.DEFAULT_TITLE_FONT, true);
return new JFreeChartPanel(chart);
}
Re: Problems !! Urgent help required!
Hi Isabelle,
Looks like we have a bug somewhere. I can't test your example easily without the rest of your code, so I did some tests with the JFreeChartDemo dynamic combined charts demo. I modified the SampleXYDataset class to vary the y-axis range, as well as the number of values in the x-axis during the test. From the four combined charts, only the third one (the overlaid chart) was updating correctly the y-axis. Therefore, you may want to test using the following code to create the charts (wrapping a normal TimeSeriesChart inside an OverlaidPlot):
CombinedPlot combinedPlot = new CombinedPlot(xAxis, CombinedPlot.VERTICAL);
OverlaidPlot overlaidPlot;
CombinedChart chartToCombine;
// add first chart as an overlaid chart
overlaidPlot = new OverlaidPlot(xAxis, yAxis1);
overlaidPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis1, data1));
chartToCombine = ChartFactory.createCombinableChart(data1, overlaidPlot);
combinedPlot.add(chartToCombine);
// add second chart as an overlaid chart
overlaidPlot = new OverlaidPlot(xAxis, yAxis2);
overlaidPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis2, data2));
chartToCombine = ChartFactory.createCombinableChart(data2, overlaidPlot);
combinedPlot.add(chartToCombine);
as a replacement to your code:
CombinedPlot combinedPlot = new CombinedPlot(xAxis, CombinedPlot.VERTICAL);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis1, data1), 1);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis2, data2), 1);
If this doesn't work, you can email me a sample file that I can run and debug.
Regards,
Bill
Looks like we have a bug somewhere. I can't test your example easily without the rest of your code, so I did some tests with the JFreeChartDemo dynamic combined charts demo. I modified the SampleXYDataset class to vary the y-axis range, as well as the number of values in the x-axis during the test. From the four combined charts, only the third one (the overlaid chart) was updating correctly the y-axis. Therefore, you may want to test using the following code to create the charts (wrapping a normal TimeSeriesChart inside an OverlaidPlot):
CombinedPlot combinedPlot = new CombinedPlot(xAxis, CombinedPlot.VERTICAL);
OverlaidPlot overlaidPlot;
CombinedChart chartToCombine;
// add first chart as an overlaid chart
overlaidPlot = new OverlaidPlot(xAxis, yAxis1);
overlaidPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis1, data1));
chartToCombine = ChartFactory.createCombinableChart(data1, overlaidPlot);
combinedPlot.add(chartToCombine);
// add second chart as an overlaid chart
overlaidPlot = new OverlaidPlot(xAxis, yAxis2);
overlaidPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis2, data2));
chartToCombine = ChartFactory.createCombinableChart(data2, overlaidPlot);
combinedPlot.add(chartToCombine);
as a replacement to your code:
CombinedPlot combinedPlot = new CombinedPlot(xAxis, CombinedPlot.VERTICAL);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis1, data1), 1);
combinedPlot.add(ChartFactory.createCombinableTimeSeriesChart(xAxis, yAxis2, data2), 1);
If this doesn't work, you can email me a sample file that I can run and debug.
Regards,
Bill
Re: Problems !! Urgent help required!
Thanx Bill for your suggestion to use overlaid charts!
Greetings,
Isabelle
Greetings,
Isabelle