ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Trend Charts
Posted by Pandey on Jun-20-2011 21:56
Hi.
I want to do a scatter plot with polynomial(2) trend line and 'mm-dd-yyyy' (in string array) as x-Axis. The problem is the scatter chart does not take string as x-Axis.
I get error in this line:
c->addScatterLayer(dataX0, dataY0, "Mapnet Scatter",Chart::DiamondSymbol, 11, 0xff0000);
I am using C++ .net

Please help.
Thanks

  Re: Trend Charts
Posted by Peter Kwan on Jun-20-2011 23:44
Hi Pandey,

The scatter layer cannot accept an array of strings as data coordinates, because strings do not have any position meaning to ChartDirector. For example, suppose the strings are {"Apple", "Oranges", "11-11-1111", "Cat"}, there is no known method that ChartDirector can know the positions of the data points.

If your intention is to use a date/time x-axis, you may pass an array of date/time to ChartDirector instead. However, in C++, there is no data type called date/time. (Some other languages, like C#, Java, VB, VB.NET, etc, do have date/time.) To address this problem, in "ChartDirector for C++", for date/time values, you would need to a number representing "calendar seconds elapsed since 0001-01-01 00:00:00". This can be constructor by using the ChartDirector utility Chart::chartTime or Chart::chartTime2.

For example:

std::vector<double> myXCoor;
for (int i = 0; i < noOfPoints; ++i)
    myXCoor.push_back(Chart::chartTime(atoi(dataX0[i]+ 3), atoi(dataX0[i]), atoi(dataX0[i] + 6)));

c->addScatterLayer(DoubleArray(&(myXCoor[0]), noOfPoints), dataY0, "Mapnet Scatter",Chart::DiamondSymbol, 11, 0xff0000);

Note that the above code assumes a date/time x-axis. You may let ChartDirector auto-scale the x-axis, or you may use Axis.setDateScale to specify the axis scale. Please do not use Axis.setLabels or Axis.setLabels2 as they are for label based x-axis.

Hope this can help.

Regards
Peter Kwan

  Re: Trend Charts
Posted by Pandey on Jun-21-2011 17:32
Hi.
Actually I am using Visual C++ 2005

My xAxis array is:
array<DateTime^,1> ^DATE = gcnew array<DateTime^,1>(15);

Now how to make it double for scatter and trend layers retaining date format?

c->addScatterLayer(DATE, YArray, ChartDirector::Chart::DiamondSymbol, 9, 0xff0000);
TrendLayer ^trend0 = c->addTrendLayer(DATE,YArray, 0xff0000);

Thanks
Pandey

  Re: Trend Charts
Posted by Peter Kwan on Jun-22-2011 02:11
Hi Pandey,

Sorry for my misunderstanding of the programming language you are using.

As you are using C++/CLI, I assume you are using ChartDirector for .NET (not ChartDirector for C++).

For this case, you may use Chart::CTime to convert from an array of DateTime to an array of double. For example:

TrendLayer ^trend0 = c->addTrendLayer(ChartDirector::Chart::CTime(DATE),YArray, 0xff0000);

Hope this can help.

Regards
Peter Kwan

  Re: Trend Charts
Posted by Pandey on Jun-22-2011 21:53
Attachments:
Thanks Peter.
I have couple of more queries:
a) Can I display the polynomial regression(2) equation on my charts trend line?  (please see the attached excel workbook)

b) Is there a way to get the standard deviation of scatter with respect to the trend line? I want to plot +-2Sigma bands w.r.t trend line (please see the attached excel workbook).

c) How can I set 'Chart Title/Scatter Layer/ Set Title'  to  Normal(non italic) fonts. The  default being Bold-Italic in Chart Director.

Regards
Pandey
ReportQuery.xls
ReportQuery.xls

113.50 Kb

  Re: Trend Charts
Posted by Peter Kwan on Jun-23-2011 05:04
Hi Pandey,

a) Can I display the polynomial regression(2) equation on my charts trend line?  (please see the attached excel workbook)

Yes. You may refer to "Parametric Curve Fitting" for an example. (One of the trend line in that example is a degree 2 polynomial regression line.)

b) Is there a way to get the standard deviation of scatter with respect to the trend line? I want to plot +-2Sigma bands w.r.t trend line (please see the attached excel workbook).

ChartDirector has built-in functions to plot line confidence band and point confidence band. See the sample code "Confidence Band". (The sample code is for linear regression, but the API also works for polynomial regression.) These bands are computed from the data points. (According to statistics, the band width for these bands should be variable along the curve.)

However, in your case, your "sigma bands" seem to be just a curve at a constant vertical distance from the trend line. In this case, you can just draw additional trend lines, using the same x-coordinates, but using y-coordinates that are +- 2 sigma (which is a constant in your case) from the original data points.

The computing the "sigma", you would need to compute it with your own code. ChartDirector can inform you the polynomial regression coefficients (see TrendLayer.getCoefficient), so you may compute it using the same method in the spreadsheet.

Hope this can help.

Regards
Peter Kwan

  Re: Trend Charts
Posted by Peter Kwan on Jun-23-2011 05:09
Hi Pandey,

I forgot to respond to your last question:

c) How can I set 'Chart Title/Scatter Layer/ Set Title'  to  Normal(non italic) fonts. The  default being Bold-Italic in Chart Director.

You may specify the font in addTitle. For example:

c->addTitle("Long Term Server Load", "Arial", 13);

Hope this can help.

Regards
Peter Kwan

  Re: Trend Charts
Posted by Pandey on Jun-23-2011 21:42
Great! Peter,the troubleshooter..
By the way.How do I get the cart director color palette codes.

I shall get back to you as and when I get stuck with Chart Director..

Thanks a lot

Pandey

  Re: Trend Charts
Posted by Peter Kwan on Jun-24-2011 05:57
Hi Pandey,

Would you mind to clarify what you are referring to by "ChartDirector color palette codes"?

Anyway, for the coloring system in general, you may refer to "Color Specification" in the ChartDirector documentation (you may look for "Color Specification" in the ChartDirector documentaton index).

Hope this can help.

Regards
Peter Kwan

  Re: Trend Charts
Posted by Pandey on Sep-01-2011 22:47
Hi! Peter,
Two questions for you:

1). I have a zooming and scrolling scatter trend (polynomial regression[2]) chart. When the image map is created, I get some spurious point indications on my trend line on 'MouseEnter'.

winChartViewer1->ImageMap = winChartViewer1->Chart->getHTMLImageMap
("clickable", "","title='X={x} Y={value}'");

When I investigated the image map by putting a 'watch' I get the following information:
////////////////////////////////////////////////////////////////////////////////////////////////
<area shape="rect" coords="96,286,105,295" title='X=2135.376256 Y=103.336639' />
<area shape="rect" coords="257,210,266,219" title='X=2325.154287 Y=120.814063' />
<area shape="rect" coords="386,152,395,161" title='X=2478.485764 Y=134.103699' />
<area shape="rect" coords="507,97,516,106" title='X=2620.811237 Y=146.825625' />
<area shape="rect" coords="93,295,102,304" title='X=2131.597245 Y=101.249581' />
<area shape="rect" coords="244,220,253,229" title='X=2310.662929 Y=118.465249' />
<area shape="rect" coords="379,161,388,170" title='X=2469.124987 Y=131.995305' />
<area shape="rect" coords="488,110,497,119" title='X=2598.018249 Y=143.775195' />
<area shape="poly" coords="70,313,577,79,577,69,70,303" title='X=2598.018249 Y=' />
<area shape="poly" coords="70,307,577,73,577,63,70,297" title='X=2598.018249 Y=' />
<area shape="poly" coords="70,319,577,85,577,75,70,309" title='X=2598.018249 Y=' />
////////////////////////////////////////////////////////////////////////////////////////////////
The top eight points are the real scatter points.But the bottom three are the spurious points that are displayed when my mouse rolls over the trendline. Also my mouse pointer turns to hand symbol when I move it on trendline.
My question is how to get rid of these spurious points and not let my mouse pointer turn to hand symbol on moving over the trendline.

2) I want the 'X' and 'Y' in the following statement:
winChartViewer1->Chart->getHTMLImageMap("clickable", "","title='X={x} Y={value}'");

display my x and y-axis parameter string that I have stored in String^ XSelect and String^ YSelect. I tried using {XSelect} and {YSelect} but were of no use. The result prints them as is.

Thanks
Pandey

  Re: Trend Charts
Posted by Peter Kwan on Sep-02-2011 00:21
Hi Pandey,

1) For the scatter trend chart, you will get image map for the scatter points, as well as the trend line. You can use Layer.setHTMLImageMap to configure different image maps for the layers. In particular, you can disable the image map for some layers.

For example:

//disable image map for myTrendLayer
myTrendLayer->setHTMLImageMap("{disable}");

2) By "x and y-axis parameter string", I assume you are referring to some text strings associated with the data points (that is, the length of the XSelect and YSelect array is the same as the number of data points).

If you would like to use custom text strings for the tooltips of your scatter points, you may use:

//register two arrays in myScatterLayer - the length of the arrays should be equal to
//the number of data points in myScatterLayer
myScatterLayer->addExtraField(XSelect);
myScatterLayer->addExtraField(YSelect);

myScatterLayer->setHTMLImageMap("clickable", "", "title='X={field0} Y={field1}'");

Hope this can help.

Regards
Peter Kwan

  Re: Trend Charts
Posted by Pandey on Sep-02-2011 22:42
Thanks Peter.
one more question for you.
When my windows XP theme changes, my winform application theme changes as per system color scheme. How to make my chart background color change with windows scheme?
For Ex how to change the following  (0x99ccccff) color with windows system scheme change:

ChartDirector::XYChart^ c = gcnew ChartDirector::XYChart(608, 381, 0x99ccccff,0x000000,ChartDirector::Chart::glassEffect(ChartDirector::Chart::NoGlare,ChartDirector::Chart::Right,35));

Pandey

  Re: Trend Charts
Posted by Peter Kwan on Sep-03-2011 02:28
Hi Pandey,

I assume you already know how to obtain the theme color in C#. After obtaining the theme color (as a Color object in C#), you may use Chart.CColor to convert it to ChartDirector format and use it as the background color. For example:

ChartDirector::XYChart^ c = gcnew ChartDirector::XYChart(608, 381, ChartDirector::Chart::CColor(myThemeColor),0x000000,ChartDirector::Chart::glassEffect(ChartDirector::Chart::NoGlare,ChartDirector::Chart::Right,35));

Hope this can help.

Regards
Peter Kwan

  Re: Trend Charts
Posted by Thair on Dec-14-2011 12:17
Thank you Peter.  You do such an excellent job in pointing people to the right direction.

Regards,
Thair