|
Show/hide and Delete options for Indicator |
Posted by aishwarya rani on Mar-30-2016 11:49 |
|
Hi,
How can i add Show/Hide & Delete options after adding an indicator to a finance chart.
How to hide an indicator?
Currently, Indicator chart looks like MACD Indicator as attached in Indicator.zip
Need to add show/hide & Delete options beside MACD in MACD Indicator
Please let me know how to add those options .
Thanks in advance
Regards,
Aishwarya Rani
|
Re: Show/hide and Delete options for Indicator |
Posted by System Administrator on Mar-31-2016 06:41 |
|
Hi Aishwarya,
For your information, apart from the method in your screenshot, in the ChartDirector sample code, there is an "Interactive Financial Chart" example that allows the user to add/remove indicators as well.
From your screenshot, it looks like you are using track cursor to generate the legend in the MACD chart, where the legend changes as the mouse moves. For simplicity, it might be easier to put the buttons on the top-right side of the plot area, as opposed to inside the constantly changing legend region.
One method to put a button on the top-right side is to put a custom text box, such as:
XYChart *macd = c->addMACD(.....);
TextBox *t = macd->addText(macd->getPlotArea()->getRightX() - 20, macd->getPlotArea()->getTopY(), "[X]", "arialbd.ttf", 8, 0x000000, Chart::TopRight);
In the above, for simplicity and ease of testing, I used "[X]" as the text. You can use an image set well by using CDML as the text, such as "<*img=/path/to/icon.png*>".
The text box can be made clickable by creating an image map:
char buffer[4096];
sprintf(buffer, "<area %s href='clickable?id=toggle_macd' title='Show/Hide MACD' />", t->getImageCoor(macd->getAbsOffsetX(), macd->getAbsOffsetY()));
...... configure chart as usual .......
viewer->setChart(c);
//Apply image map after setChart
viewer->setImageMap(buffer);
Now in the BN_CLICKED handler, you should be able to determine that if the above button have been clicked by checking the "id" parameter (which is set to toggle_macd in the above code).
The above is for one button. You can add multiple text boxes for multiple buttons. For the image map, please append them into one text string before calling setImageMap.
In the BN_CLICKED handler, you can then set a flag to indicate if the indicator should be visible, then redraw the chart.
I am not exactly sure what would happen if the indicator is hidden. I assume even if the indicator is hidden, the legend box will still be there, the button will be gone to, and there is no way to show the indicator again. One method to create an indicator that just contains the legend box is like:
// Use a small height of the indicator so that it just contain the legend box and set
// the y-axis margin to the same height to push the chart outside the plot area.
XYChart *macd = c->addMACD(16, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000);
macd->yAxis()->setMargin(16);
macd->yAxis()->setColors(Chart::Transparent, Chart::Transparent);
... use addText to add buttons .....
So in your charting code, if the flag indicates the indicator is visible, draw the indicator as usual, otherwise use the above method to draw just the legend box part of the indicator (with the track cursor still functional).
Regards
Peter Kwan |
|