|
Stacked Area Chart Tooltips |
Posted by L on Feb-27-2015 22:10 |
|
Hello,
I'm having some trouble with tooltips on a stacked area chart, and I wondered if you
might have any advice. We're generating our own tooltips, and it works great for the most
part. The stacked area chart presents a bit of a problem. Of course we want the mouse
hover "hot spot" to reflect the stacked data, and then we want the tooltip to show the raw
value. That's no problem -- I have access to both the stacked values and the raw values.
I'm using an algorithm that finds the nearest data point in x and y from each trace and
then I select the winning trace by finding the point that is closest in stacked y value while
still being north of the mouse. This works in most cases, but it misses when you're
hovering on a location where there really isn't a near data point and the nearest may be
on a much more distant trace that has a point with a close y. I suppose it'd be easier if I
could draw an example, but I suspect you'll know what I mean. If I'm hovering on an
area that's shaded red, I really want the tooltip to be for the red trace, but sometimes
there will be a data point that is closer on some other trace.
Is there an easier way to do this using the API? Can ChartDirector tell me which trace I'm
really hovering over? Perhaps can it tell me the color of the area shading at the mouse
position?
Thanks,
L |
Re: Stacked Area Chart Tooltips |
Posted by Peter Kwan on Feb-28-2015 01:54 |
|
Hi L,
Are you using the image maps generated by ChartDirector to define the "hot spots" for
the tooltips, or are you using your own method to determine the data point associated
with a region?
ChartDirector can generate image maps to define the "hot spots" on the chart, which
should meet your requirement. The exact code depends on your programming language
and whether you are writing a web or desktop application. The should be some sample
code include in ChartDirector to demonstrate how to use the image map for tooltips. The
tooltips in the sample code are usually standard tooltips provided by the operating
system or the web browser. If you need a special tooltip box or text, there are also be
sample code that shows how you can attach your own event handler to the hot spots.
In addition to the image maps, you may also consider to use "Programmable Track Cursor"
to display information for data points near the mouse.
If you need more specific information, please let me know which programming language
edition of ChartDirector you are using.
For your information, if you want to use your own algorithm to to determine which region
the mouse is hover on, you may consider the following method, which is roughly the
method used by ChartDirector to generate the image map:
(a) Given a mouse coordinate, determine the next x-data coordinate and previous x-data
coordinate, ignoring the y-coordinates.
(b) Starting from the first data set (the one at the bottom of the stack), the area for
this data set between these two x-coordinates must be a trapezium. It is easy to
determine if the mouse is within this trapezium. If it is not, then try the next data set,
and so on.
(c) One you identify the data set, the data point is the point with the x-coordinate
nearest to the x-coordinate of the mouse.
Hope this can help.
Regards
Peter Kwan |
|