TimeSeriesChart: can't change ValueAxis range

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jfreechart175371
Posts: 8
Joined: Tue Mar 18, 2014 2:00 pm
antibot: No, of course not.

TimeSeriesChart: can't change ValueAxis range

Post by jfreechart175371 » Fri Jun 20, 2014 1:08 pm

Hello. I would really appreciate some help on the below. I am trying to change the range of my primary (value) axis but it's not displaying the values along the axis or the line graph anymore.

The below code worked fine except I wasn't satisfied with the range, as the range was defaulted:

Code: Select all

               JFreeChart chart = ChartFactory.createTimeSeriesChart(
												        tkr, // title
													"Time", // x-axis label
													"Last", // y-axis label
													ds1, // data
													false, // create legend?
													true, // generate tooltips?
													false // generate URLs?
													);
			chart.setBackgroundPaint(Color.white);
			XYPlot plot = (XYPlot) chart.getPlot();
			plot.setBackgroundPaint(Color.lightGray);
                        XYItemRenderer renderer = plot.getRenderer();
                        renderer.setPaint(Color.white);
But the below doesn't display the values of the value axis nor the graph and i don't know why:

Code: Select all

                        JFreeChart chart = ChartFactory.createTimeSeriesChart(
													tkr, // title
													"Time", // x-axis label
													"Last", // y-axis label
													ds1, // data
													false, // create legend?
													true, // generate tooltips?
													false // generate URLs?
													);
			chart.setBackgroundPaint(Color.white);
			XYPlot plot = (XYPlot) chart.getPlot();
			plot.setBackgroundPaint(Color.lightGray);
                        NumberAxis yAxis = (NumberAxis)plot.getRangeAxis();
			yAxis.setRange(124.104, 124.401);
			yAxis.setTickLabelPaint(Color.black);
                        XYItemRenderer renderer = plot.getRenderer();
                       renderer.setPaint(Color.white);
Could someone please instruct me how to only change the range of the ValueAxis without losing the other properties? Thank you very much for your time.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: TimeSeriesChart: can't change ValueAxis range

Post by paradoxoff » Fri Jun 20, 2014 3:22 pm

The subject is misleading, as you have apparently been able to change the range, or at least you have no proof that the attempted change of the range was not done.
To me, it seems like that you are using a wrong NumberTickUnit that is so large that it doesn´t contain any visible Tick between 124.104 and 124.401. This should only happen if you use a manually defined NumberTickUnit, but there is no hint in the code snippet you have provided. I guess that there is an important snippet missing.

jfreechart175371
Posts: 8
Joined: Tue Mar 18, 2014 2:00 pm
antibot: No, of course not.

Re: TimeSeriesChart: can't change ValueAxis range

Post by jfreechart175371 » Fri Jun 20, 2014 3:49 pm

Thank you for the reply. I have not changed the TickUnitCount. I subsequently add axis on the right side of the chart, and they display as usual. When I click on the chart, zoom in, zoom out, I then see the data being graphed and the left hand axis at least has values, but different than the range I specified. Perhaps you are right in that all I need to do is correctly set the unit tick size as well? I have multiple charts and so I don't want to have to click on a chart for it to work properly, besides it disturbs the axi on the right.

jfreechart175371
Posts: 8
Joined: Tue Mar 18, 2014 2:00 pm
antibot: No, of course not.

Re: TimeSeriesChart: can't change ValueAxis range

Post by jfreechart175371 » Fri Jun 20, 2014 4:11 pm

You are absolutely correct.

I had assumed the problem was the above code in connection with the generation of the axis. Rather, the problem was code I wasn't sharing which generated the range. I couldn't imagine the problem was there.

Thank you very much for your time.

Locked