|
Polar chart troble with dynamically addZone |
Posted by WNKR10 on Sep-05-2013 19:31 |
|
I use c++ and MFC and did Sector Zones example on Radar/Polar Charts at MFC Demo.
I modified it to 360 degrees and make 360 hot spot for every degree on the border of the chart. In drawChart function i can call addZone function like this:
c->angularAxis()->addZone(10, 50, 0xffff00);
and the zone appeares, but i want to make it like when i click on one hotspot and after that on another to call addZone with this 2 points and draw the zone.
I implement OnChart() to handle hotspots:
void CSimplezoomscrollDlg::OnChart()
{
ImageMapHandler *handler = m_ChartViewer.getImageMapHandler();
if (0 != handler)
{
const char *path = handler->getValue("path");
if ((0 != path) && (0 != *path))
{
int htspot = handler->getHotSpot(m_ChartViewer.getChartMouseX(), m_ChartViewer.getChartMouseY());
}
}
}
Can you help me where and how to call addZone?
Regards,
WNKR10 |
Re: Polar chart troble with dynamically addZone |
Posted by Peter Kwan on Sep-06-2013 02:01 |
|
Hi WNKR10,
You can put the addZone in the same place as your current "c->angularAxis()->addZone(10, 50, 0xffff00);" code. You just need to modify the code so that instead of hard coding it to (10, 50), you change it to whatever the user has clicked.
In the simplest case, you can create two member variables in your CSimplezoomscrollDlg class to keep track of the zone positions:
class CSimplezoomscrollDlg : public CDialog
{
private:
double zoneStart;
double zoneEnd;
......
};
Then in the constructor, please initialize the variables to Chart::NoValue (or -1 or some values you can recognize to mean empty):
zoneStart = Chart::NoValue;
zoneEnd = Chart::NoValue;
Now in your charting code, instead of:
c->angularAxis()->addZone(10, 50, 0xffff00);
you can change it to:
if ((zoneStart != Chart::NoValue) && (zoneEnd != Chart::NoValue))
c->angularAxis()->addZone(zoneStart, zoneEnd, 0xffff00);
So to create the zone, just set the values to zoneStart and zoneEnd, then redraw the chart.
Finally, you can set up a user interface go set values to zoneStart and zoneEnd. If you want to use mouse clicks on hot spot to do this, you may use something like:
void CSimplezoomscrollDlg::OnChart()
{
ImageMapHandler *handler = m_ChartViewer.getImageMapHandler();
//check if the chart has an image map
if (0 != handler)
{
//check if clicking on a hot spot that is a data point
const char *x = handler->getValue("x");
if ((0 != x) && (0 != *x))
{
double angle = atof(x);
//first click - set zoneStart, second click - set zoneEnd and redraw chart
if (zoneStart == Chart::NoValue)
zoneStart = angle;
else if (zoneEnd == Chart::NoValue)
{
zoneEnd = angle;
m_ChartViewer.updateViewPort(true, true);
}
else
{
//In this example, ignore further clicks
}
}
}
}
Hope this can help.
Regards
Peter Kwan |
Re: Polar chart troble with dynamically addZone |
Posted by WNKR10 on Sep-06-2013 04:49 |
|
Great help! I've managed to do it slightly different, but think your way is cleaner and ill try it tomorrow and write the results!
10x ! |
Re: Polar chart troble with dynamically addZone |
Posted by WNKR10 on Sep-09-2013 17:53 |
|
It works perfectly, but would you help me do it instead of clicking two times, i want to drag from one hotspot to other and then call addZone with this two hotspots.
How to use startDrag and dragTo..?
Help will be greatly appreciated!
Regards,
WNKR |
Re: Polar chart troble with dynamically addZone |
Posted by Peter Kwan on Sep-10-2013 00:34 |
|
Hi,
In the mouse down event handler (OnLButtonDown), you may use the ImageMapHandler to determine which hot spot the mouse is over. In the mouse up event handler (OnLButtonUp), you may use the ImageMapHandler to determine which hot spot the mouse is over. In this way, you can obtain the two hot spots for your zone.
Hope this can help.
Regards
Peter Kwan |
|