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

Message ListMessage List     Post MessagePost Message

  Location on Spline
Posted by Josh on Jun-24-2010 04:33
Hello,

I've used the code you posted in http://www.chartdir.com/forum/download_thread.php?
bn=chartdir_general&thread=1153402586 to generate a bell curve.  Instead
of having a vertical line indicating values, I would rather have a circle (or other symbol)
directly on the line of the bell curve itself.  I apologize that I am not familiar enough with
your library to know if it's capable of doing this and if so, how it's done.

Thanks for any help you can give me.

Josh

  Re: Location on Spline
Posted by Peter Kwan on Jun-24-2010 16:29
Attachments:
Hi Josh,

You may use a scatter layer to put symbols on anywhere you like on the chart. I have modified the code as attached to use a scatter layer instead of a mark line.

If you would like the label to occur on top of the scatter symbol (or near the scatter symbol), you may add a data label to the symbol using Layer.addCustomDataLabel.

Hope this can help.

Regards
Peter Kwan
normaldist.png
normaldist.asp
<%@ language="vbscript" %>
<%
Set cd = CreateObject("ChartDirector.API")

normalDistribution = Array(0.011,0.044,0.135,0.325,0.607,0.882,1.000, _
	0.882,0.607,0.325,0.135,0.044,0.011)

'Create a XYChart object of size 250 x 250 pixels
Set c = cd.XYChart(600, 300)

'Set the plotarea at (30, 20) and of size 200 x 200 pixels
Call c.setPlotArea(50, 20, 500, 250, cd.Transparent, cd.Transparent, cd.Transparent, _
	cd.Transparent, cd.Transparent)
Call c.yAxis().setColors(cd.Transparent, cd.Transparent)

'Add a line chart layer using the given data
Set layer = c.addSplineLayer(normalDistribution)

midPoint = UBound(normalDistribution) / 2
Call c.xAxis().setLinearScale2(0, Ubound(normalDistribution), Nothing)
Call c.xAxis().addLabel(midPoint, "AAAA")
Call c.xAxis().addLabel(midPoint + 2, "BBBB")
Call c.xAxis().addLabel(midPoint - 2, "CCCC")
 
Call c.addScatterLayer(Array(midPoint), Array(normalDistribution(midPoint)), "", cd.CircleSymbol, 11, &Hff0000)

Call c.addInterLineLayer(c.yAxis().addMark(0, 0).getLine(), layer.getLine(), _
	c.xZoneColor(midPoint - 2, cd.Transparent, c.xZoneColor(midPoint + 2, &Heeeeee, cd.Transparent)))

'output the chart
Response.ContentType = "image/png"
Response.BinaryWrite c.makeChart2(cd.PNG)
Response.End
%>

  Re: Location on Spline
Posted by Josh on Jun-24-2010 21:15
Thank you for the reply.  The only problem is what if I need to place the value between two
points (such as the 1/3 of the way between CCCC and AAAA)?

I've currently hacked a method of doing this by checking pixel colors to find the spline line
(since getXCoor works but getYCoor does not).  I'd prefer to do it through the library if
possible.

Thanks!

Josh

  Re: Location on Spline
Posted by Peter Kwan on Jun-25-2010 01:03
Hi Josh,

The curve you are plotting is a normal distribution curve. It is defined by the well known normal distribution formula. See:

http://en.wikipedia.org/wiki/Normal_distribution

You can use this formula to compute any point on the curve you like.

For example, if you want to put a point at a position 0.7 standard deviation above the mean, you may use the above formula to compute the value, and then put it at:

x = midPoint + 2 * 0.7
y = Exp(- 0.7 * 0.7/2) * normalDistribution(midPoint)

Hope this can help.

Regards
Peter Kwan