You can reference this image for this example: http://www.brayjones.com/images/graph.gif
My code is:
--------------------------------------------------------
XYDataset dataset = new TimeSeriesCollection(trendseries);
XYItemRenderer renderer1 = new VerticalXYBarRenderer(0.20);
NumberAxis axis = new VerticalNumberAxis("Covered Amount");
axis.setAutoRangeIncludesZero(true);
axis.setLowerMargin(0.00);
XYPlot subplot1 = new XYPlot(dataset, null, axis, renderer1 );
XYDataset dataset2 = new TimeSeriesCollection(trendseries2);
XYItemRenderer renderer2 = new StandardXYItemRenderer();
XYPlot subplot2 = new XYPlot(dataset2, null, new VerticalNumberAxis("YTD Covered"), renderer2);
//Marker m = new Marker(750.00, new Color(0xCCCCCC), new Color(0xCCCCCC), 0);
//subplot2.addDomainMarker(m); ????
DateAxis xAxis = new HorizontalDateAxis("Date Of Service");
//xAxis.setVerticalTickLabels(true); ????
CombinedXYPlot plot = new CombinedXYPlot(xAxis, CombinedXYPlot.VERTICAL);
plot.add(subplot2, 2); // a weight of 2 (50%)
plot.add(subplot1, 2); // a weight of 2 (50%)
JFreeChart chart2 = new JFreeChart("Covered Charges",
JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart2.setBackgroundPaint(new Color(0xFFFFFF));
--------------------------------------------
I've purchased the PDF documentation and looked at the demo code but still can't see the light. A little help please.
Question 1: How can I draw a bar across the graph at $750.00 on the bar chart? Same for top chart also.
Question 2: How can I format the numbers to dollars on the left of both graphs?
Question 3: How can I get the dates on the bottom to turn vertical with the format of mm/dd/yy.
Question 4: How can I get the dates to spread out with a few days inbetween so I just don't get the month/year only (two months)?
Thanks a bunch for the help. I spent all day yesterday trying to figure these out but seem to be applying the methods to the wrong objects. I'm also new to java so give me a little slack.
BTW- The documentation purchased is a big help. You might want to consider some examples in the details also.
Thanks again for any help.
Bray
DateAxis, Markers, formatter
Re: DateAxis, Markers, formatter
Bray Jones wrote:
> Question 1: How can I draw a bar across the graph at $750.00
> on the bar chart? Same for top chart also.
Use the code you commented out, but use setRangeMarker(...) instead of setDomainMarker(...). This will draw a horizontal line at 750.0, it marks a value against the range (vertical) axis.
> Question 2: How can I format the numbers to dollars on the
> left of both graphs?
Slightly tricky at the moment, at least if you want to leave the auto-tick-unit-selection mechanism on. If you don't need auto-tick-unit-selection, then you can do this:
NumberFormat formatter = new DecimalFormat("$#,##0.00");
NumberTickUnit unit = new NumberTickUnit(500.0, formatter);
If you *do* want auto-tick-unit-selection, you will need to copy-and-paste the createStandardTickUnits() method from the NumberAxis class, and change each of the DecimalFormat objects that are used (to include a $). Then you can call the setStandardTickUnits(...) method in the NumberAxis class to install your new collection.
Someone else asked a similar question yesterday (or the day before) concerning date axis formatting. I think in the next release I will provide a format override option for the auto-tick-unit-selection mechanism.
> Question 3: How can I get the dates on the bottom to turn
> vertical with the format of mm/dd/yy.
To change the orientation, use the setVerticalTickLabels(...) method in the HorizontalDateAxis class. Changing the format is a similar problem as for the NumberAxis in (2) (assuming you have JFreeChart 0.9.4).
> Question 4: How can I get the dates to spread out with a few
> days inbetween so I just don't get the month/year only (two
> months)?
That will happen automatically when you flip the labels to vertical, because now there should be enough room to display the next smaller 'standard' tick size, without the labels overlapping.
If you want to set a fixed tick size, use the setTickUnit(...) method in the DateAxis class.
> Thanks a bunch for the help. I spent all day yesterday
> trying to figure these out but seem to be applying the
> methods to the wrong objects. I'm also new to java so give
> me a little slack.
I'll clarify any of the above if you need more info - just ask.
> BTW- The documentation purchased is a big help. You might
> want to consider some examples in the details also.
I'm continuing to add examples to the documentation - I don't think you can have too many...
Regards,
DG.
> Question 1: How can I draw a bar across the graph at $750.00
> on the bar chart? Same for top chart also.
Use the code you commented out, but use setRangeMarker(...) instead of setDomainMarker(...). This will draw a horizontal line at 750.0, it marks a value against the range (vertical) axis.
> Question 2: How can I format the numbers to dollars on the
> left of both graphs?
Slightly tricky at the moment, at least if you want to leave the auto-tick-unit-selection mechanism on. If you don't need auto-tick-unit-selection, then you can do this:
NumberFormat formatter = new DecimalFormat("$#,##0.00");
NumberTickUnit unit = new NumberTickUnit(500.0, formatter);
If you *do* want auto-tick-unit-selection, you will need to copy-and-paste the createStandardTickUnits() method from the NumberAxis class, and change each of the DecimalFormat objects that are used (to include a $). Then you can call the setStandardTickUnits(...) method in the NumberAxis class to install your new collection.
Someone else asked a similar question yesterday (or the day before) concerning date axis formatting. I think in the next release I will provide a format override option for the auto-tick-unit-selection mechanism.
> Question 3: How can I get the dates on the bottom to turn
> vertical with the format of mm/dd/yy.
To change the orientation, use the setVerticalTickLabels(...) method in the HorizontalDateAxis class. Changing the format is a similar problem as for the NumberAxis in (2) (assuming you have JFreeChart 0.9.4).
> Question 4: How can I get the dates to spread out with a few
> days inbetween so I just don't get the month/year only (two
> months)?
That will happen automatically when you flip the labels to vertical, because now there should be enough room to display the next smaller 'standard' tick size, without the labels overlapping.
If you want to set a fixed tick size, use the setTickUnit(...) method in the DateAxis class.
> Thanks a bunch for the help. I spent all day yesterday
> trying to figure these out but seem to be applying the
> methods to the wrong objects. I'm also new to java so give
> me a little slack.
I'll clarify any of the above if you need more info - just ask.
> BTW- The documentation purchased is a big help. You might
> want to consider some examples in the details also.
I'm continuing to add examples to the documentation - I don't think you can have too many...
Regards,
DG.
Re: DateAxis, Markers, formatter
Thanks... I tried most of those already but it was in version 0.9.1. When I successfully upgrade to 0.9.4 I'll try it again.
Thanks DG.
Thanks DG.