Question about timestamp values ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
haloween
Posts: 1
Joined: Tue Mar 19, 2019 5:02 am
antibot: No, of course not.

Question about timestamp values ?

Post by haloween » Tue Mar 19, 2019 5:05 am

Hi!
Could somebody help me with this one...
I'm a beginner in java programming and i have this (simple?) problem using jfreechart.
How can I get timestamp values of my vector to label for the X-axis?

Here's the code so far...:


public class Temperature extends ApplicationFrame {

protected XYSeries series1;

public Temperature(String title) {

super(title);

Vector v1 = new Vector ();
Vector v2 = new Vector ();

for (int k=100000; k<100100; k++) // example

{
Timestamp aika = new Timestamp(k);

v1.add(c);
System.out.println("Now = "+c);
double factor = 10 + 10.6*Math.random(); //just random temp values
Double d = new Double(factor);
v2.add(d);
System.out.println("Temperature= "+d);
}

this.series1 = new XYSeries("Temperature"); //kuvaaja 1

for (int i=0; i<v1.size(); i++)
{
String joo = (String) v1.get(i);
String jee = (String) v2.get(i);

this.series1.add(new Double(joo),new Double(jee));
}

XYSeriesCollection dataset = new XYSeriesCollection(series1);

JFreeChart chart = ChartFactory.createXYChart("Lämpötila-arvojen seuranta", "Aika", "°C", dataset, true);
XYPlot plot = chart.getXYPlot();

ValueAxis axis = plot.getDomainAxis();

axis = plot.getRangeAxis();
axis.setRange(0.0, 200.0);

JPanel content = new JPanel(new BorderLayout());
ChartPanel chartPanel = new ChartPanel(chart);
this.setContentPane(chartPanel);
}


public static void main(String[] args) {

Temperature demo = new Temperature("Lämpötilan mittaus");
demo.pack();
demo.setVisible(true);
}

}
Top

John Matthews
Posts: 483
Joined: Wed Sep 12, 2007 3:18 pm

Re: Question about timestamp values ?

Post by John Matthews » Tue Mar 19, 2019 5:14 pm

Have you looked at ChartFactory.createTimeSeriesChart(), aut seq.?

Post Reply