|
Multi select on Scatter chart |
Posted by Alexander on Dec-11-2007 23:27 |
|
how to code multi select point on Scatter chart?
I want to make a similar mouse select points of spotfire...
|
Re: Multi select on Scatter chart |
Posted by System Administrator on Dec-12-2007 02:58 |
|
Hi Alexander,
The exact details depends on your programming langauge, development framework, application type (eg. web or windows), operating systems, etc..
In general, ChartDirector charts can have mouse events, like mouse down and mouse move, etc.. You can handle the mouse events to allow the user to drag a rectangle over the chart. Then you can translate the rectangle bounds into axis scale. (You can obtain the axis scale using Axis.getMinValue and Axis.getMaxValue). Based on the axis scale, you can determine which of your data points are within the bounds of the rectangle.
Hope this can help.
Regards
Peter Kwan |
Re: Multi select on Scatter chart |
Posted by Zev Toledano on Dec-30-2009 16:39 |
|
I too am looking for a way to do this but your reply is unclear on how to go about converting rectangle coordinates to data points. Here are a few problems/questions that come to mind:
1. Is there some API that can help me find all the data points in all the layers and data series included in the rectangle or do I write my own function that goes over my original data arrays value by value?
2. What happens with axes with nominal/discrete values? I would have to translate the strings to their positions in the graph and calculate somehow if the graph position overlaps the rectangle coordinates?
3. What about stacked bars? In this case, each segment is displayed in the 'wrong' place in the graph (i.e. if the value is 1 but it's on top of another segment, its position in the graph would be 2+)
4. What about 3d graphs/overlapping bars/etc?
5. What about pie/donut/spider/etc graphs?
What's really needed here is an event or method that gives me an array of datapoints for a rectangle... is this possible? |
Re: Multi select on Scatter chart |
Posted by Peter Kwan on Dec-30-2009 22:59 |
|
Hi Zev,
The suggestion in this thread works mostly for scattered chart, in which the data are represented as points.
In general, the data may not be points, but may be represented as an arbitrary shape (depends on chart type). In some programs, a shape is considered as selected if any part of it is within the bounding rectangle. In some programs, a shape is selected only if the whole shape is in the bounding rectangle. Your code will have to decide how to select a shape.
There is in fact an API that returns the coordinates of everything in a standard format. The API is called BaseChart.getHTMLImageMap. It works with pie, bar, line, donut, spider, etc.. The returned coordinates are returned in a standard format called HTML. Your code can parse the HTML <area> tags to obtain the information you need.
Hope this can help.
Regards
Peter Kwan |
Re: Multi select on Scatter chart |
Posted by Zev Toledano on Dec-31-2009 01:31 |
|
Thank you. That sounds like it would cover all my questions. I guess I'll try writing a function that makes use of it soon...
Ideally, since you already have the code that converts x,y to data points, an API that does this for you with rectangles would be cool. |
Re: Multi select on Scatter chart |
Posted by Peter Kwan on Dec-31-2009 10:46 |
|
Hi Zev,
To convert from a data value (x, y) to pixel (x, y), the API is BaseChart.getXCoor and BaseChart.getYCoor. To do the reverse, you need two additional API Axis.getMaxValue and Axis.getMinValue, and perform linear interpolation. For example:
double xStart = mainPriceChart.xAxis().getMinValue();
double xEnd = mainPriceChart.xAxis().getMaxValue();
double xStartPixel = mainPriceChart.getXCoor(xStart);
double xEndPixel = mainPriceChart.getXCoor(xEnd);
//linear interpolation
double xValueOfMouse = (xPixelOfMouse - xStartPixel) * (xEnd - xStart) / (xEndPixel - xStartPixel) + xStart;
To get the coordinates of a rectangle, just perform the above for 2 opposite corners of the rectangle.
The BaseChart.getHTMLImageMap is an API for getting the coordinates of data representation, which are "shapes" (not points). The shapes can be a rectangle, but usually not a rectangle. (They area currently rectangles only for 2D bar segments and symbols. For 3D bar segments, they are hexagons. For line segments, they can be hexagons or parallelograms. For area charts, they can be hexagons, pentagons, or trapeziums, ....)
Hope this can help.
Regards
Peter Kwan |
|