How can I get the maximal visible value?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
roadrunner
Posts: 4
Joined: Wed Nov 19, 2003 6:39 pm

How can I get the maximal visible value?

Post by roadrunner » Wed Dec 03, 2003 2:08 pm

I want to automatically resize my y-axis depending on the values displayed (setAutoRange(true) will not work).

Expanding the rage work fine. I want reduce the axis length, if the last value is 70% of the maximal visible value. But I cannot find a way to get the max. visible value for calculating a minor value for y-axis.

Any idea?

Kartik
Posts: 21
Joined: Fri Nov 07, 2003 8:17 am

Reduce Y-Axis length

Post by Kartik » Thu Dec 04, 2003 1:54 pm

Hi,

Try using the following code to reduce the axis length

Code: Select all

CategoryPlot plot = chart.getCategoryPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
Range rangeData = rangeAxis.getRange();

rangeData = new Range(rangeData.getLowerBound(),rangeData.getUpperBound());
rangeAxis.setRange(rangeData);
Hope this is of help to you.

regards,

Kartik

roadrunner
Posts: 4
Joined: Wed Nov 19, 2003 6:39 pm

Re: Reduce Y-Axis length

Post by roadrunner » Thu Dec 04, 2003 3:56 pm

Kartik,
unfortunately not. I tried upperBound() before. But it seems to return the upperBound of all values. Not only the visible values. I think it will than work, if I can delete the values not visible in my dataset. But
a) I don't know how to do it. I use a TimeSeriesCollection and there is no delete method and no repace method I also searched to reduce my datapoints.
b) Later I will support a different mode with scrollbar, so there I need the older values.

Did you or anyone else another possibility? I used to track it by my own, but it is always correct, because I don't know the real timeframe actually displayed.

Guest

Post by Guest » Thu Dec 04, 2003 6:03 pm

Theoretic it could work with:

Code: Select all

chartPanel.autoRangeVertical()
but the call doesn't work. For the horizontal axist it work. I use it there for unzooming.

So I do it now outside with my onw tracking. It works, but it could be better if it would be integrated in jFreeChart, or if I can get the maximum value of the drawn values.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Dec 04, 2003 6:40 pm

At the moment there is no support in JFreeChart for obtaining the range of values for the visible points only. That is something that I want to introduce (at least for time series charts) to make it easier to work with large time series (for example, you might want to plot the most recent 3 months of a 10 year time series). It is on the to-do list, but I have no idea when I will get to it...
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

kingguppy
Posts: 37
Joined: Mon Apr 07, 2003 9:52 pm
Location: Wuppertal, Germany

Post by kingguppy » Thu Dec 04, 2003 7:33 pm

I've implemented this, it's one of the many patches I'll be submitting soon.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Dec 04, 2003 7:39 pm

Great! I have also seen your patch re: tooltips which sounds like a good idea, I just haven't had time to look closely at it yet.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

George

Replaceing last value of a time series

Post by George » Fri Dec 05, 2003 1:19 pm

kingguppy wrote:I've implemented this, it's one of the many patches

I'll be submitting soon.
That's great :D I hope David will integrate it soon.

Also very useful and not too much too implement - I think - will be a possibility to replace a value - espeacially the last - with a new value. Or much better only with a new time.

Background:
I have a dynamic chart. To update the time I have to add a new value to the same value and the new time. In this way I get a lot of not needed values. Espeacially, if user choose a short update time. It will be much better, if I had the possibility to change the timestap of the last value. In this case, the time will go on and I don't need to blow up my collection.

roadrunner

roadrunner
Posts: 4
Joined: Wed Nov 19, 2003 6:39 pm

Workaround

Post by roadrunner » Mon Dec 15, 2003 6:45 pm

I did the following workaround (if someone will help this):

calculates vertical range:

Code: Select all

	public void checkVerticalBounds() {
		try {
			long time = getDataset().getTime();
			if(time-fBoundcheckStarttime > getVisibleTimeRange()) {
				int seriesCount = getDataset().getSeriesCount();
				for (int series = 0; series < seriesCount; series++) {
					// 	Falls noch nicht initialisiert
					if(fMaxValues[0][series]==0) {
						fMaxValues[0][series]=fMaxValues[1][series];
					}
					if(fMaxValues[0][series]*0.7 > fMaxValues[1][series] && fMaxValues[1][series] > 0) { // neuer Wert kleiner 70% des alten Höchstwertes
						fValueAxis[series].setRange(0, fMaxValues[1][series]*1.1); // Anzeigenhöhe verkleinern
					}	
					// reinit maxValueSammler
					fMaxValues[0][series] = fMaxValues[1][series]; 	// neuer maxValue
					fMaxValues[1][series] = 0;				// Sammler rücksetzen		
				}
				fBoundcheckStarttime=getDataset().getTime();
			}

		} catch (Exception e) {
			System.err.println("Excep");e.printStackTrace();
		}
	}

Gets the actual timerange for the x-axis

Code: Select all

	private long getVisibleTimeRange() {
		if (fVisibleTimeRange == 0) {
			fVisibleTimeRange = 60000; // 60 secunden
		}
		return fVisibleTimeRange;
	}

Locked