|
Countour Scatter: fill entire plot area? |
Posted by Vince on Mar-21-2012 01:07 |
|
I am trying to draw a countour layer (heatmap) from scatter data.
However I am not able to make Chart Director fill the entire plot area.
It looks as if the interpolated layer is indeed calculated (see the orange strip at the top-
right end) but it gets cropped by the convex polygon drawn around the scatter points.
Am I missing something? What am I doing wrong?
Here is my very simple code (adapted from one of the examples)
<%@ language="vbscript" %>
<%
Set cd = CreateObject("ChartDirector.API")
' The (x, y, z) coordinates of the scattered data
dataX = Array(0.5, 1.9, 4.9, 1.0, 8.9, 9.8, 5.9, 2.9, 6.8, 9.0, 0.0, 8.9, 1.9, 4.8, _
2.4, 3.4, 7.9, 7.5, 4.8, 7.5, 9.5, 0.4, 8.9, 0.9, 5.4, 9.4, 2.9, 8.9, 0.9, 8.9, _
10.0, 1.0, 6.8, 3.8, 9.0, 5.3, 6.4, 4.9, 4.5, 2.0, 5.4, 0.0, 10.0, 3.9, 5.4, _
5.9, 5.8, 0.3, 4.4, 8.3)
dataY = Array(3.3, 3.0, 0.7, 1.0, 9.3, 4.5, 8.4, 0.1, 0.8, 0.1, 9.3, 1.8, 4.3, 1.3, _
2.3, 5.4, 6.9, 9.0, 9.8, 7.5, 1.8, 1.4, 4.5, 7.8, 3.8, 4.0, 2.9, 2.4, 3.9, 2.9, _
2.3, 9.3, 2.0, 3.4, 4.8, 2.3, 3.4, 2.3, 1.5, 7.8, 4.5, 0.9, 6.3, 2.4, 6.9, 2.8, _
1.3, 2.9, 6.4, 6.3)
dataZ = Array(6.6, 12.5, 7.4, 6.2, 9.6, 13.6, 19.9, 2.2, 6.9, 3.4, 8.7, 8.4, 7.8, _
8.0, 9.4, 11.9, 9.6, 15.7, 12.0, 13.3, 9.6, 6.4, 9.0, 6.9, 4.6, 9.7, 10.6, 9.2, _
7.0, 6.9, 9.7, 8.6, 18.0, 13.6, 13.2, 5.9, 9.0, 3.2, 8.3, 9.7, 8.2, 6.1, 8.7, _
5.6, 14.9, 9.8, 9.3, 5.1, 10.8, 9.8)
' Create a XYChart object
Set c = cd.XYChart(600, 424)
' Set the plotarea. Use semi-transparent black (c0000000) for both horizontal and
vertical grid lines
Call c.setPlotArea(0, 0, 600, 424, -1, -1, -1, &Hc0000000, -1)
' Add a contour layer using the given data
Set oLayer = c.addContourLayer(dataX, dataY, dataZ)
call oLayer.setContourColor(cd.Transparent)
call oLayer.setSmoothInterpolation(1)
' Get the Color Axis, specify colors and gradient
Set oAxis = oLayer.ColorAxis
aryColor = Array(&H00FF7000,&H00FFB300,&H00FFFF00,&H0099CC00,&H00339900)
call oAxis.setColorGradient(0, aryColor, -1, -1)
' Set the color axis range as 0 to 20, with a step every 4 units
Call oAxis.setLinearScale(0, 20, 4)
' Output the chart
Response.ContentType = "image/png"
Response.BinaryWrite c.makeChart2(cd.PNG)
Response.End
%>
Thanks in advance for your attention.
Vince
|
Re: Countour Scatter: fill entire plot area? |
Posted by Peter Kwan on Mar-22-2012 00:11 |
|
Hi Vince,
ChartDirector can only fill the region within the convex hull of the data points. (The currently ChartDirector algorithm only uses "interpolation" for surface fitting, not "extrapolation".) The convex hull may or may not be rectangular depending on the data points. If the convex hull is not rectangular, it may not completely fill the rectangular plot area. So what you see is normal.
If you must fill the plot area, you may consider to artifically add 4 points at the 4 corners, which are (xMax, yMax), (xMax, yMin), (xMin, yMax), (xMin, yMin), where xMax, xMin, yMax, yMin are the maximum and minimum values of the x and y coordinates. For the z coordinate at those points, you may need to guess a value. (A typical method is to find the z coordinate of the nearest data point, or a weight average of the z values based on the distance of the data points, or to simply use 0 or a fixed value or the average z value.)
Hope this can help.
Regards
Peter Kwan |
|