Saurabh,
Just added a new example chart titled "World's Simplest Line Chart
Editor" that shows you how to add points to a Client-side GChart curve
by clicking on empty space on the chart (you'll need to download the
latest v2.4 version of Cllient-side GChart to use this code):
Code:
http://gchart.googlecode.com/svn/trunk/gcharttestapp/src/com/googlecode/gchart/gcharttestapp/client/GChartExample22.java
Screen-shot:
http://gchart.googlecode.com/svn/trunk/gchart/src/com/googlecode/gchart/client/doc-files/gchartexample22.png
This example will eventually make its way into GChart's Chart Gallery,
but for now you have to grab them directly from subversion using the
links above.(Don't forget to add the chart to the RootPanel and call
the chart's update method--these steps are not included in the code
above. See note at top of the Chart Gallery for details),
I've pasted in the key lines from this example below, which transform
from client to model coordinates. The first two code lines use generic
GWT methods that anyone who just need to shift the origin of the
client coordinates to the upper left corner of the current element
could use (after removing the GChart calls from these two lines):
// 1st, translate mouse client x,y coordinates into
// pixel distances from upper-left of plot area:
double xPx = Window.getScrollLeft()
+ Event.getCurrentEvent().getClientX()
- getAbsoluteLeft()
- getYAxis().getAxisLabelThickness()
- getYAxis().getTickLabelThickness()
- getYAxis().getTickLength();
double yPx = Window.getScrollTop()
+ Event.getCurrentEvent().getClientY()
- getAbsoluteTop()
- getChartTitleThickness();
// 2nd, transform those pixel offsets to model units:
double x = getXAxis().getAxisMin()*(1-xPx/getXChartSize()) +
getXAxis().getAxisMax()*(xPx/getXChartSize());
// note the pixelY-to-cartesianY min/max swap
double y = getYAxis().getAxisMax()*(1-yPx/getYChartSize()) +
getYAxis().getAxisMin()*(yPx/getYChartSize());
// add point, using the model units:
getCurve().addPoint(insertionPoint++, x, y);
HTH,
On Jan 28, 12:34 am, John Gunther <
johncurtisgunt...@yahoo.com> wrote:
> Client-sideGChart2.4 was just released today, It supports click
> events, so that might help you. Unfortunately,
> there are still no client to model coordinate conversion functions.
> Please consider adding a request for this feature to theGChartissue
> tracker. In the meantime, looking at the setClientX, setClientY,
> xToPixel, yToPixel internal methods inGChart.java might help you to
> implement such conversion functions on your own (I had considered
> adding a clientToModel method within the Axis class for 2.4, which is
> where I think this fits into the current API).
>
> Appreciate hearing that you found the product helpful.
>
> John C. Guntherhttp://
gchart.googlecode.com
> > Thanks for developing a great product likeGChartwhich integrates so
> > easily with GWT and works like charm. I had a query - I want to draw a
> > chart where I can click on any point along the x-y axis to determine
> > the point cordinates in model units. Once I get that, I can do an
> > addPoint() to add the point to the curve.
>
> > I tried doing that inGChartbut I did not find any methods through
> > which I can handle a mouse click event to get the x-y cordinates in
> > model units. I can get the cordinates by implementing an EventListener
> > for the chart but those cordinates are of the browser window and in
> > different units. So it does not help. How can we accomplish this in
> >GChart?
>
> > Also, asGChartis a subclass of widget, I can use widget's methods on
> > it. But as Curve, Point are classes enclosed withinGChart, I cannot