Hey Guy's
First of all thanks for all the help In my previous questions really help!!
I have finally gotten a plot to show up in my application but have some questions about setting up the axis. I want the x axis to show the hours of a specfied day but right now it only shows the hours for which there is data. I think it is autoranging but not sure. So what I want is static x axis range from 00:00-23:00. Can I also make the Y axis to some static range?
My last question relates to plotting a series. As the code stands now I am manually giving in random data for testing. I have a file that has the real times and y value saved in the following form.
25/09/2002 11:42:45:796 50
...
..
.
Reading the data out to stings is no problem but how can I modify
Fun.add(new Hour(1,new Day()),12);
to take 11:42:45:796 as the time stamp (I was thinking I could possibly work in milliseconds but maybe there may better way)
I posted my code bellow for reference
private void MakeGraph(){
//Function to Setup The Data Graph
BasicTimeSeries Data;
BasicTimeSeries Fun = new BasicTimeSeries("Quarterly Data",Hour.class);
Fun.add(new Hour(1,new Day()),12);
Fun.add(new Hour(3,new Day()),1);
Fun.add(new Hour(12,new Day()),4);
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(Fun);
JFreeChart chart = ChartFactory.createTimeSeriesChart("New Plot","Time","FlowRate",dataset,false);
//CategoryPlot plot = chart.getCategoryPlot();
chart.setBackgroundPaint(new Color( 212,208,200));
XYPlot plot = chart.getXYPlot();
HorizontalDateAxis axis = (HorizontalDateAxis)plot.getDomainAxis();
axis.setTickUnit(new DateUnit(Calendar.HOUR_OF_DAY, 1));
axis.getTickLabelFormatter().applyPattern("hh:mm");
ChartPanel chartPanel = new ChartPanel(chart);
jPanel16.add(chartPanel,BorderLayout.CENTER);
};
AutoRange Questions
Re: AutoRange Questions
Hi Marty,
(1) The axis range is calculated automatically by default. But you can easily set the axis range manually using the setRange(...) method in the ValueAxis class.
For example:
XYPlot plot = myChart.getXYPlot();
ValueAxis axis = plot.getRangeAxis();
axis.setRange(0.0, 5.0);
There is also a setRange method that accepts a Range object as the argument. DateRange, a subclass of Range, can make it a bit easier to set the range for a date axis:
DateRange range = new DateRange(date1, date2);
ValueAxis domainAxis = plot.getDomainAxis();
domainAxis.setRange(range);
(2) For your real time data, I would recommend using the Millisecond class.
Regards,
DG.
(1) The axis range is calculated automatically by default. But you can easily set the axis range manually using the setRange(...) method in the ValueAxis class.
For example:
XYPlot plot = myChart.getXYPlot();
ValueAxis axis = plot.getRangeAxis();
axis.setRange(0.0, 5.0);
There is also a setRange method that accepts a Range object as the argument. DateRange, a subclass of Range, can make it a bit easier to set the range for a date axis:
DateRange range = new DateRange(date1, date2);
ValueAxis domainAxis = plot.getDomainAxis();
domainAxis.setRange(range);
(2) For your real time data, I would recommend using the Millisecond class.
Regards,
DG.
Re: AutoRange Questions
Thanks the axis stuff works!!
But I think something is still wrong
I made a date range from 0 to 86400000 to span a whole day.
But now my axis starts off with a blank then 02:00, 03:00, 04:00.......23:00, 00:00, blank, This does not seem right should it not start at 00:00 and go to 23:00,blank? How can I do This ?
But I think something is still wrong
I made a date range from 0 to 86400000 to span a whole day.
But now my axis starts off with a blank then 02:00, 03:00, 04:00.......23:00, 00:00, blank, This does not seem right should it not start at 00:00 and go to 23:00,blank? How can I do This ?
Re: AutoRange Questions
That will give you one day starting at midnight GMT on 1 Jan 1970. I'm pretty sure the axis will then display this in local time (but I can't remember without digging out the code).
You probably want to create two java.util.Date instances (using a Calendar for your locale) and set the axis range using these.
Regards,
DG.
You probably want to create two java.util.Date instances (using a Calendar for your locale) and set the axis range using these.
Regards,
DG.
Re: AutoRange Questions
It worked but the It still won't label 00:00 at the start of the axis any ideas