|
Trying to "Combine" a Surface Chart with a Scatter Chart |
Posted by Scott on Oct-17-2013 18:03 |
|
We are evaluating ChartDirector for possible use in our company and are specifically interested in whether or not ChartDirector can combine a Surface Chart created using one set of scattered data (data points are randomly distributed rather than lying on a grid) and then combine on that Surface Chart a second set of scattered data (which has many fewer data points, probably less than 50 in total) to be shown in a ?Scattered Chart? format.
Attached is a ?mock up? of what such a chart might look like.
Essentially we have two different data sets, the first one having thousands of data points, which we would like to represent as a Surface Chart, and the second data set, which will have round 50 data points, which we would like to represent as a Scatter Chart ?combined? onto the Surface Chart.
Reviewing the documentation for the Surface Chart Class as well as the Scatter Chart Class, it was not obvious how one could possible accomplish this goal of showing these two data sets in such a manner. At first we though one might be able to use the ?addScatterGroups? method to ?add? the Scatter Chart to the Surface Chart, but upon further review it does not appear that this approach would work with the Surface Chart.
The other possible approach that we?ve considered is whether or not you could ?Combine? two independently generated Charts and then ?Combine? them as described in the second screen grab below from your web site. We were thinking perhaps one would create one of the charts with ?transparency? and the other chart without walls and floor, and then layer one chart on top of the other chart. Not certain which chart would be better to have as the ?transparent? chart, but we believe it probably would be the Surface Chart that should be semi-transparent (with solid walls and floor) and the Scatter Chart should be generated with the exact same scaling and ?perspective?, but without walls or floor and layered on top of the Surface Chart.
The issue with this approach that we think we?re going to have is that any Scatter Chart data points that should be hidden behind the ?peaks? of the Surface Chart will be visible and thus throw off the appearance of the Chart.
Any help and assistance you can provide on how to go about generating a Chart like the one mocked up below would be greatly appreciated.
Thank you,
Scott
|
Re: Trying to "Combine" a Surface Chart with a Scatter Chart |
Posted by Peter Kwan on Oct-17-2013 23:55 |
|
Hi Scott,
Unluckily, ChartDirector does not have a chart type that have both a surface chart and 3D scatter symbols.
ChartDirector does allow you to overlay two charts together. So you can create a 3D scatter chart with just the points visible and overlay it on the surface chart. In your message, you are already aware of the limitation of this approach - that the "z-order" will not be correct. Scatter symbols that should be hidden under the surface, behind the peak or partial hidden (if the surface happens to cut the symbol into two halves) will still be completely visible.
To overlay two charts together, the code is (in C#/Java):
//put chart2 over chart1
DrawArea d2 = chart2.makeChart3();
chart1.makeChart3().merge(d2, 0, 0, Chart.TopLeft, 0);
In your case, you would need to make sure:
(a) chart2 is created using Transparent as the background color, and everything except the scatter symbols is disabled or set to transparent. The plot region walls can be disabled by using ThreeDChart.setWallVisibility, and the axis can be made complete transparent with Axis.setColors.
(b) The plot region position, size and view angles of the two charts should be configured the same way.
(c) The axis scales of the two charts should be the same. If the axis scales are automatically determined by ChartDirector. ChartDirector may not use the same scales for both charts as they contain different data. So we suggest your code to use Axis.setLinearScale to specify the axis scale. You just need to specify the max and min values to use, in which those values can be determined by considering both your surface data and scatter data, plus some margins. ChartDirector can still be used to automatically determine the labels on the axis.
If you can inform me of your programming language and your application type (eg. a web application or desktop application), I can write an example for you.
Regards
Peter Kwan |
Re: Trying to "Combine" a Surface Chart with a Scatter Chart |
Posted by Tim on Jul-14-2016 23:30 |
|
Hi Peter,
The task described here is exactly what I am exploring at the moment. I have just licensed your software and am trying to catch up.
I create a Surface Chart first, and now wish to create a Scatter Chart to make an overlay exactly. Here are the steps:
For Chart 2 (scatter chart):
1 - Set same plot area and extent as those of Chart 1 (surface chart);
2 - Set transparency
c2->setTransparentColor(0xffffff);
c2->setWallVisibility(0, 0, 0);
c2->xAxis()->setColors(Chart::Transparent);
c2->yAxis()->setColors(Chart::Transparent);
3 - Set same min and max range (for each X/Y/Z axis) as those of Chart 1
Please help and provide an example in C#. (I wish to get the dynamic ranges from Chart 1 and then set those to the new Chart 2, but could not figure this out quickly.
4 - Add data to Chart 2
e.g.
c2->addScatterGroup(DoubleArray(xData, 1), DoubleArray(yData, 1), DoubleArray(zData, 1), "", Chart::GlassSphere2Shape, 11, Chart::SameAsMainColor);
5 - Put Chart 2 over Chart 1 and save the new merged file
Any example for this step? use MultiChart?
Thanks
Tim |
Re: Trying to "Combine" a Surface Chart with a Scatter Chart |
Posted by Peter Kwan on Jul-15-2016 02:13 |
|
Hi Tim,
Below please find an example for your reference. Basically, it is the original "Surface Chart" sample code, merged with a 3D Scatter Chart.
// The x and y coordinates of the grid
double dataX[] = {-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
double dataY[] = {-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// The values at the grid points. In this example, we will compute the values using the formula
// z = x * sin(y) + y * sin(x).
double dataZ[(int)(sizeof(dataX) / sizeof(dataX[0])) * (int)(sizeof(dataY) / sizeof(dataY[0]))];
for(int yIndex = 0; yIndex < (int)(sizeof(dataY) / sizeof(dataY[0])); ++yIndex) {
double y = dataY[yIndex];
for(int xIndex = 0; xIndex < (int)(sizeof(dataX) / sizeof(dataX[0])); ++xIndex) {
double x = dataX[xIndex];
dataZ[yIndex * (int)(sizeof(dataX) / sizeof(dataX[0])) + xIndex] = x * sin(y) + y * sin(
x);
}
}
// Create a SurfaceChart object of size 720 x 600 pixels
SurfaceChart *c = new SurfaceChart(720, 600);
// Add a title to the chart using 20 points Times New Roman Italic font
c->addTitle("Surface Energy Density ", "timesi.ttf", 20);
// Set the center of the plot region at (350, 280), and set width x depth x height to 360 x 360
// x 270 pixels
c->setPlotRegion(350, 280, 360, 360, 270);
// Set the data to use to plot the chart
c->setData(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))), DoubleArray(dataY,
(int)(sizeof(dataY) / sizeof(dataY[0]))), DoubleArray(dataZ, (int)(sizeof(dataZ) / sizeof(
dataZ[0]))));
// Spline interpolate data to a 80 x 80 grid for a smooth surface
c->setInterpolation(80, 80);
// Add a color axis (the legend) in which the left center is anchored at (645, 270). Set the
// length to 200 pixels and the labels on the right side.
c->setColorAxis(645, 270, Chart::Left, 200, Chart::Right);
// Set the x, y and z axis titles using 10 points Arial Bold font
c->xAxis()->setTitle("X (nm)", "arialbd.ttf", 10);
c->yAxis()->setTitle("Y (nm)", "arialbd.ttf", 10);
c->zAxis()->setTitle("Energy Density (J/m<*font,super*>2<*/font*>)", "arialbd.ttf", 10);
// Auto-scale axis so we can get the axis scale
c->layout();
RanSeries *r = new RanSeries(3);
DoubleArray xData = r->getSeries(20, 0, -3, 3);
DoubleArray yData = r->getSeries(20, 0, -3, 3);
DoubleArray zData = r->getSeries(20, 5, -5, 5);
ThreeDScatterChart *c2 = new ThreeDScatterChart(720, 600, Chart::Transparent);
c2->setWallVisibility(false, false, false);
c2->setPlotRegion(350, 280, 360, 360, 270);
c2->addScatterGroup(xData, yData, zData, "", Chart::GlassSphere2Shape, 13, Chart::SameAsMainColor);
c2->xAxis()->syncAxis(c->xAxis());
c2->yAxis()->syncAxis(c->yAxis());
c2->zAxis()->syncAxis(c->zAxis());
c->makeChart()->merge(c2->makeChart(), 0, 0, Chart::TopLeft,0);
c->makeChart("aaa.png");
delete c2;
delete c;
Regards
Peter Kwan
|
Re: Trying to "Combine" a Surface Chart with a Scatter Chart |
Posted by Tim on Jul-15-2016 09:45 |
|
Hi Peter - Thanks for the very helpful response. With this concept, one can make very sophisticate charts, and what is all needed is imagination! Best wishes, Tim. |
|