valueToJava2D - wrong X,Y values in chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
serhan
Posts: 10
Joined: Tue Jul 05, 2005 9:03 am

valueToJava2D - wrong X,Y values in chart

Post by serhan » Wed Jan 25, 2006 6:42 pm

Hi
I will tell the whole story...
The task is to draw in a Timeseries chart items as vertical lines, the line length should be the lenght of my items, that means :
I have objects which has begin time and end time, the line should start in the begin time and ends in the end time, to do this I built another time serieses for the end times but didn't display them, and then override the getItemShape function to make it create a line shape for the item in the series.
I use the getXValue and getYvalue for each point and then use valueToJava2D with the value and the (domainAxisEdge,rangeAxisEdge) and the PROBLEMATIC one dataArea as the second parameter......
if I use the plotArea or dataArea the items in the chart displayed in the wrong places, but if I use like this

Code: Select all

Rectangle2D rect = new Rectangle2D.Double(0,0,0,0);
valueToJava2D(endYValue,  rect, yEdge);
this diplay all the items and in the right places, but not in the required length....... this is the part of code which do it:

Code: Select all

private Shape createShape(BusinessActionInstance bai, Rectangle2D dataArea, int series, int item) {

		RectangleEdge xEdge = getPlot().getDomainAxisEdge();
		RectangleEdge yEdge = getPlot().getRangeAxisEdge();

//		Rectangle2D rect = new Rectangle2D.Double(0, 0, 700, 250);
		//		Rectangle2D rect = new Rectangle2D.Double(0,0,0,0);

		double beginXValue = this.dataset.getXValue(series, item);
		double endXValue = this.dataset.getXValue(series + 6, item);
		double beginYValue = this.dataset.getYValue(series, item);
		double endYValue = this.dataset.getYValue(series, item);

		double x1 = getPlot().getDomainAxis().valueToJava2D(beginXValue, dataArea, xEdge);
		double x2 = getPlot().getDomainAxis().valueToJava2D(endXValue, dataArea, xEdge);
		double y1 = getPlot().getRangeAxis().valueToJava2D(beginYValue, dataArea, yEdge);
		double y2 = getPlot().getRangeAxis().valueToJava2D(endYValue, dataArea, yEdge);

		// if((x2 - x1) < 1) x2 = x1 + 5;
		Double line = new Line2D.Double(x1, y1, x2, y2);

		return ShapeUtilities.createLineRegion(line, 2.0f);
	}

Can you please help me to draw the items in the same place with the rigth length...

Thanks

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Wed Jan 25, 2006 9:50 pm

Have you tried getting the actual dataArea of the chart using

Code: Select all

Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Depending on the orientation of the chart you might also need to flip the x and y values

serhan
Posts: 10
Joined: Tue Jul 05, 2005 9:03 am

valueToJava2D - wrong X,Y values in chart

Post by serhan » Thu Jan 26, 2006 9:59 am

Hi
Well since I extend the XYLineAndShapeRenderer I override the drawItem function to make it send the dataArea , so YES, I use the dataAraea (I cant use ChartPanel since I'm not working in a panel, it's web application)

What do you mean by FLIP the x and y 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 Jan 26, 2006 11:01 am

It is very important that you pass in a rectangle (dataArea) that matches the chart as it has been drawn.

If you are sure you have the correct dataArea, then perhaps the problem is that your endXValue uses 'series+6' and your endYValue uses just 'series'.
David Gilbert
JFreeChart Project Leader

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

serhan
Posts: 10
Joined: Tue Jul 05, 2005 9:03 am

Explanation

Post by serhan » Thu Jan 26, 2006 2:26 pm

HI
I want an explanation about this :
Why when I use the dataArea (doesn't matter if it's the chart size or the plot size - I even tried to give similar values like this
Rectangle2D.Double(0, 0, 700, 250); or
Rectangle2D.Double(75, 4, 693, 402); etc') I get the items not in the right place in the domain axis BUT , If I do the following
dataArea = new Rectangle2D.Double(0, 0, 0, 0);
I get the items in the right place but not in the right length of the line...

Why is this ?

About the series+6 in the endXValue and not in the endYvalue, it dosen't make a different, because The Y are the same for the item in the series and the item in the series+6

Serhan

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 Jan 26, 2006 3:05 pm

What type of axes do you have? If you look in the source code for the valueToJava2D() method in the NumberAxis class, you'll see that for an area equal to new Rectangle2D.Double(0.0, 0.0, 0.0, 0.0) you'll always get a return value of zero. Which makes me think you have some sort of customised axis...
David Gilbert
JFreeChart Project Leader

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

Locked