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

Message ListMessage List     Post MessagePost Message

  Adding Extra Fields to 3D Scatter Chart
Posted by Jane Wilson on Jul-06-2016 01:58
Hi! I'm using php and trying to create a 3D Scatter Chart with labels on each of the data points - is that possible?


# The data for the bar chart
$data = array($BK_E1_0052_pcnt, $BK_E2_0341_pcnt, $BK_E3_0261_pcnt, $BK_E4_0171_pcnt, $BK_E5_0271_pcnt, $BK_E6_0252_pcnt, $BK_E7_0211_pcnt, $BK_E8_0321_pcnt, $BK_E9_0161_pcnt);

# The XYZ data for the 3D scatter chart as 3 random data series
$r = new RanSeries(3);
$xData = $r->getSeries2(20, 100, -9, 9);
$yData = $r->getSeries2(20, 100, -9, 9);
$zData = $data;

# Create a ThreeDScatterChart object of size 720 x 520 pixels
$c = new ThreeDScatterChart(720, 520);

# Add a title to the chart using 20 points Times New Roman Italic font
#$c->addTitle("3D Scatter Chart (2)  ", "timesi.ttf", 20);

# Set the center of the plot region at (350, 240), and set width x depth x height to 360 x 360 x 270
# pixels
$c->setPlotRegion(350, 240, 360, 360, 270);

# Set the elevation and rotation angles to 15 and 30 degrees
$c->setViewAngle(15, 30);

# Add a scatter group to the chart using 13 pixels glass sphere symbols, in which the color depends
# on the z value of the symbol
$g = $c->addScatterGroup($xData, $yData, $zData, "Sites", GlassSphere2Shape, 13, SameAsMainColor);

# Add labels to the chart as an extra field
$g->addExtraField("BES", "CES", "DES", "EES", "MES", "PGES", "SHES", "SES", "WES");

# Add grey (888888) drop lines to the symbols
$g->setDropLine(0x888888);

# Add a color axis (the legend) in which the left center is anchored at (645, 220). Set the length
# to 200 pixels and the labels on the right side. Use smooth gradient coloring.
$colorAxisObj = $c->setColorAxis(645, 220, Left, 200, Right);
$colorAxisObj->setColorGradient();

# Set the x, y and z axis titles using 10 points Arial Bold font
#$c->xAxis->setTitle("X-Axis Place Holder", "arialbd.ttf", 10);
#$c->yAxis->setTitle("Y-Axis Place Holder", "arialbd.ttf", 10);
$c->zAxis->setTitle("% of Goal", "arialbd.ttf", 10);

# Output the chart
#header("Content-type: image/png");
#print($c->makeChart2(PNG));
$chart_BES_MO_URL = $c->makeSession("chart_BES_MO");
# Create an image map for the chart
$imageMap_BES_MO = $c->getHTMLImageMap("cylinderbar.php");

I can create the chart just fine without the addExtraField parameter but when I include it, I get this message:
Fatal error: Call to undefined method ThreeDScatterGroup::addExtraField() 

Is it possible for me to add labels to each of the points?
Thanks,
Jane

  Re: Adding Extra Fields to 3D Scatter Chart
Posted by Peter Kwan on Jul-07-2016 00:16
Hi Jane,

You would need to use BaseChart.addText to label the symbols in the ThreeDScatterChart. It is like:

.... create the chart as usual ....

#auto-scale the axis
$c->layout();

for ($i = 0; $i < count($xData); ++$i) {
    $xCoor = $c->getXCoor($xData[$i], $yData[$i], $zData[$i];
    $yCoor = $c->getYCoor($xData[$i], $yData[$i], $zData[$i]);
    $c->addText($xCoor, $yCoor, $data[$i], "arialbd.ttf", 8, 0x000000, Left);
}

Hope this can help.

Regards
Peter Kwan