In the above, the (leftX, topY), (rightX, bottomY) are the pixel coordinates of the top-left corners and bottom-right corners of your DrawArea in the chart that you are displaying (the chart that you put to the chart viewer). Since your code draw the DrawArea, it should have all the information.
In the above, I have set the id attribute to myDrawArea as an example. If your chart has multiple clickable objects, in the mouse click event handler, you can check this attribute to determine if the object clicked is the DrawArea.
I am using vector<CPoint> ptNode to collect all drawing coordinates of each drawing object, not just a rectangular shape, it could be any,
I left an id for each object, now I need to know how to put this correctly in the image map,
I embedded my custom shape drawing process, have append the imagemap and call
m_chartViewer->setImageMap(c->getHTMLImage("") after m_chartViewer->setChart(c) inside the drawChart loop. But I doesn't work.
Thanks in advance, and looking forward to hear from you soon!
Basically, you just need to specify your shape as an <AREA> tag. The shape can be a circle, rectangle or polygon. If the object contains more than one shape, you can use more than one <AREA> tag. ChartDirector can understand the <AREA> tag and use it to determine where is the hotspot.
Note the the coordinates used needs to be in the pixel coordinate system of the chart in the CChartViewer. I am not sure how you draw using the DrawArea. If you draw on the underlying DrawArea of the chart (obtained using c->getDrawArea() or c->makeChart()), then it is already using the coordinate system of the chart. If you create a standalone independent DrawArea object, draw things on it, and then put it onto the chart at position (x, y), then the coordinates you use the to draw the object will be offsetted by (x, y) in the chart coordinate system. That means you would need to add (x, y) to your coordinates in the <AREA> tag to express them in the chart coordinate system.
You may have many <AREA> tags if you have many objects, and you may also ask ChartDirector to generate hotspots for the chart objects. Since the image map are just text strings, you can append them together and then pass them to setImageMap. It is like:
std::string myImageMap = "<AREA ....."; //image map for DrawArea object 1
myImageMap += "<AREA ...."; // image map for DrawArea object 2 (if any)
myImageMap += c->getHTMLImageMap(.....); //image map for other chart objects