|
Chart Title |
Posted by Pandey on Nov-21-2013 19:21 |
|
Hi!
1. How do I remove the previous chart title that I added on my XYchart (managed c++).
I am doing the following, but nothing happens. My new title over laps the previous one:
//Remove the previous Title
c->addTitle2(Chart.Top," ");
c->addTitle2(Chart::BottomLeft," ");
c->addTitle2(Chart::BottomCenter, " ");
MainComWinChartViewer->updateDisplay(true);
//MainComWinChartViewer->updateViewPort(true,true);
//Add new title
c->addTitle2(Chart.Top,"\\n"+"Combined Data"+"\\n"+PT->T2TB->Text+"\\n"+PT->T3TB->Text, "Tahoma Bold", 9.75);
c->addTitle2(Chart::BottomLeft,today->ToString("D") ,"Tahoma", 8.0);
c->addTitle2(Chart::BottomRight, "Curve#: " + PT->CurveNoTB->Text,"Tahoma", 8.0);
c->addTitle2(Chart::BottomCenter, PT->FNTB->Text,"Tahoma", 8.0);
2. While debugging can I see the realtime change on my MainComWinChartViewer chart as my code executes line-by-line?
Thanks,
Pandey |
Re: Chart Title |
Posted by Peter Kwan on Nov-21-2013 23:17 |
|
Hi Pandey,
In general, you cannot delete an object added to ChartDirector, and you cannot modify the chart object after it has already been displayed. To modify a chart, please create a new chart object. Because ChartDirector can create a new chart in tens of millseconds, so creating a new chart object can be very fast and smooth. Also, usually no additional code is needed to create a new chart. You can just use the same subroutine that creates the chart in the first place.
There are many examples in ChartDirector in which the charts are updated by creating a new one. For example, in the Zooming and Scrolling examples, the zooming and scrolling are achieved by creating a new chart. In the Realtime chart examples, the chart is updated by creating a new chart.
For your case, you may create a "drawChart" function that draws the chart and displays it. The drawChart function should add a title to the chart, in which the title text is in member variable (lets call it myTitle). When you need to change the title, you just need to do:
myTitle = "\\n"+"Combined Data"+"\\n"+PT->T2TB->Text+"\\n"+PT->T3TB->Text;
drawChart();
There is actually a method to modify the chart display after it has already been displayed - to use the dynamic layer (see BaseChart.initDynamicLayer). The dynamic layer can only draw simple objects, like simple shapes, text, lines, etc.. You need to draw using the DrawArea object, instead of the XYChart object. You can imagine the dynamic layer as an additional DrawArea layer floating on top of the XYChart layer. ChartDirector uses the dynamic layer to implement programmable track cursors. (You can image a mouse cursor - wherther the standard "pointer" or "hand" cursor, or the programmable track cursor - to be something floating on top of the chart and not really part of the chart.)
You can see the change in the MainComWinChartViewer when you set the chart object to MainComWinChartViewer or call updateDisplay. You cannot see any change in MainComWinChartViewer if your code do not change MainComWinChartViewer. For example, if you execute the following code:
c->addTitle("ABC");
then nothing will change in MainComWinChartViewer because the above code does not use MainComWinChartViewer.
Hope this can help.
Regards
Peter Kwan |
Re: Chart Title |
Posted by Pandey on Nov-22-2013 13:51 |
|
Thanks, Peter
The following code works, but I am unable to place the title(d->test) on the centre of the title area. Is there a way to do that?
DrawArea^ d = c->initDynamicLayer();
PlotArea^ plotArea = c->getPlotArea();
String^myTitle="\\n"+"Combined Data"+"\\n"+PT->T2TB->Text+"\\n"+PT->T3TB->Text;
d->text(myTitle, "Arial Bold", 9.75,50,20,0x00000ff);
MainComWinChartViewer->Chart=c;
Thanks again.
@Pandey |
Re: Chart Title |
Posted by Peter Kwan on Nov-22-2013 23:44 |
|
Hi Pandey,
You may include an alignment parameter when drawing text. The sample code "Track Line with Axis Labels" uses this method to draw text in the dynamic layer and position the text to be right aligned or left aligned. You can use TopCenter alignment for your case. It is like:
d->text(myTitle, "Arial Bold", 9.75)->draw(50,20,0x00000ff,Chart.TopCenter);
Hope this can help.
Regards
Peter Kwan |
|