|
Tooltips on 3D scatterchart |
Posted by Chris Taylor on Dec-21-2023 11:45 |
|
I have implemented a 3D scatterchart with connectng lines as below. Is it possible to add tooltips when the user hovers over a point similar to using setHTMLImageMap on a 2D chart? I noticed a post from 2009 that indicated this may not be supported but hoping something has changed.
void CustomPanel::Create3DChart(){
// The XYZ data for the 3D scatter chart as 3 random data series
int numDataPoints = 20;
RanSeries* r = new RanSeries(2);
DoubleArray xData = r->getSeries(numDataPoints, 100, -10, 200); //numPoints, startingVal, minVal, maxVal
DoubleArray yData = r->getSeries(numDataPoints, 0, 0, 200);
DoubleArray zData = r->getSeries(numDataPoints, 100, -10, 1000);
//data that represents 'speed' our fourth param (for 4D charting)
DoubleArray speedData = r->getSeries(numDataPoints, 0, 500);
// Create a ThreeDScatterChart object of size 720 x 600 pixels
//ThreeDScatterChart* c = new ThreeDScatterChart(720, 600);
this->d = new ThreeDScatterChart(720, 600);
// Add a title to the chart using 20 points Times New Roman Italic font
d->addTitle("Altitude vs Latitude vs Longitude vs Speed", "Times New Roman Italic", 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
d->setPlotRegion(350, 280, 360, 360, 270);
// Add a scatter group to the chart using 11 pixels glass sphere symbols, in which the color
// depends on the z value of the symbol
d->addScatterGroup(xData, yData, zData, "", Chart::GlassSphere2Shape, 11, Chart::SameAsMainColor);
// Auto-scale the axis
d->layout();
// Draw the line segments - color is based on speed value
for (int i = 1; i < numDataPoints; ++i){
int xCoor = d->getXCoor(xData[i - 1], yData[i - 1], zData[i - 1]);
int yCoor = d->getYCoor(xData[i - 1], yData[i - 1], zData[i - 1]);
int xCoor2 = d->getXCoor(xData[i], yData[i], zData[i]);
int yCoor2 = d->getYCoor(xData[i], yData[i], zData[i]);
if (speedData[i] < 125.00) {
d->addLine(xCoor, yCoor, xCoor2, yCoor2, 0xff0000, 1);
}
else if(speedData[i] < 250.00) {
d->addLine(xCoor, yCoor, xCoor2, yCoor2, 0x0000ff, 1);
}
else if (speedData[i] < 375.00) {
d->addLine(xCoor, yCoor, xCoor2, yCoor2, 0x00ff00, 1);
}
else {
d->addLine(xCoor, yCoor, xCoor2, yCoor2, 0x000000, 1);
}
}
// 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.
d->setColorAxis(645, 270, Chart::Left, 200, Chart::Right);
// Set the x, y and z axis titles using 10 points Arial Bold font
d->xAxis()->setTitle("Latitude", "Arial Bold", 10);
d->yAxis()->setTitle("Longitude", "Arial Bold", 10);
d->zAxis()->setTitle("Altitude", "Arial Bold", 10);
threeD_chartViewer->setChart(d);
} |
Re: Tooltips on 3D scatterchart |
Posted by Peter Kwan on Dec-21-2023 16:23 |
|
Hi Chris,
The 3D scatter chart sample code in recent versions of ChartDirector have all included tooltips. The following is an example:
void threedscatter(CChartViewer *viewer, int /* chartIndex */)
{
// The XYZ data for the 3D scatter chart as 3 random data series
RanSeries* r = new RanSeries(0);
DoubleArray xData = r->getSeries(100, 100, -10, 10);
DoubleArray yData = r->getSeries(100, 0, 0, 20);
DoubleArray zData = r->getSeries(100, 100, -10, 10);
// Create a ThreeDScatterChart object of size 720 x 600 pixels
ThreeDScatterChart* c = new ThreeDScatterChart(720, 600);
// Add a title to the chart using 20 points Times New Roman Italic font
c->addTitle("3D Scatter Chart (1) ", "Times New Roman Italic", 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);
// Add a scatter group to the chart using 11 pixels glass sphere symbols, in which the color
// depends on the z value of the symbol
c->addScatterGroup(xData, yData, zData, "", Chart::GlassSphere2Shape, 11, Chart::SameAsMainColor
);
// 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-Axis Place Holder", "Arial Bold", 10);
c->yAxis()->setTitle("Y-Axis Place Holder", "Arial Bold", 10);
c->zAxis()->setTitle("Z-Axis Place Holder", "Arial Bold", 10);
// Output the chart
viewer->setChart(c);
//include tool tip for the chart
viewer->setImageMap(c->getHTMLImageMap("clickable", "", "title='x={x|p}, y={y|p}, z={z|p}'"));
//free up resources
delete r;
}
Best Regards
Peter Kwan
|
Re: Tooltips on 3D scatterchart |
Posted by Chris Taylor on Jan-04-2024 06:08 |
|
thank you Peter,
I am just back from my holiday break and will try implemting this now. Thank you for the quick response! |
Re: Tooltips on 3D scatterchart |
Posted by Chris Taylor on Jan-04-2024 07:18 |
|
Hi Peter,
Can I confirm this is possible using Chart Director with WX Widgets (using C++ with WX ChartDir)? I'm thinking your example may only be possible for MFC applications? |
Re: Tooltips on 3D scatterchart |
Posted by Chris Taylor on Jan-04-2024 09:38 |
|
I should mention in the context of my code:
threeD_chartViewer->setChart(d);
threeD_chartViewer is a wxChartViewer. I cannot use a CChartViewer *viewer as it is undefined. |
Re: Tooltips on 3D scatterchart |
Posted by Peter Kwan on Jan-05-2024 02:26 |
|
Hi Chris,
The wxChartViewer is not from us. It is from one of our customers that port the ChartDirector C++ "ChartViewer" to wxWidgets. We have not tried wxChartViewer ourselves, but from our experience supporting other customers that use wxWidgets, it works every well, and I believe it supports tooltips.
In C++, there are dozens of GUI frameworks with no standard. As it is not practical for us to support so many GUI frameworks in C++, we only provide implementations for MFC and Qt (the CChartViewer and QChartViewer). We open source the CChartViewer and QChartViewer so other developers can port them to other frameworks. One of our customers ported the CChartViewer to wxWidgets and released it to the public. That's why there is a wxChartViewer available.
You can simply replace the "viewer" to your wxChartViewer, like:
threeD_chartViewer->setChart(c);
threeD_chartViewer->setImageMap(c->getHTMLImageMap("clickable", "", "title='x={x|p}, y={y|p}, z={z|p}'"));
Best Regards
Peter Kwan |
|