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

Message ListMessage List     Post MessagePost Message

  Surface Chart Labels
Posted by Adrian Groves on Mar-04-2011 20:50
Hi there,

I want to be able to produce a 3D surface chart with both the X & Y axes to be based on
string values, and the Z-axis on a number. I cannot see how to do this.

In the documentation there is an example of such a chart with a label Y-axis, a date/time
X-axis and a numeric Z-axis.

I have tried passing an array of numbers to the Y-axis, then using an array of labels via
addExtraField and {field0} but this does not seem to work.

Any ideas ?

Ade

  Re: Surface Chart Labels
Posted by Peter Kwan on Mar-05-2011 00:36
Hi Adrian,

You can use labels for any axis and all axes. For example:

$c->xAxis->setLabels($anArrayOfLabels);
$c->yAxis->setLabels($anotherArrayOfLabels);

If you use a label based axis, the coordinates for the data points are the index position of the labels (0, 1, 2, 3, ...). For example, an x-coordinate of 0 means the position at the first x-axis label. An y-coordinate of 7 means the position at the 8th y-axis label. So for your case, the x and y coordinates should both be integers 0, 1, 2, ....

If you left out either the x or y coordinates (eg. by using a null array), but not both, ChartDirector will automatically determine the array size of the missing array. ChartDirector can do so as it assumes the data points are in a rectangular grid, so the x/y/z array sizes are related by x_array_size x y_array_size = z_array_size. After determining the array size of the missing array, it assumes its contents are the index (0, 1, 2, ....).

Hope this can help.

Regards
Peter Kwan

  Re: Surface Chart Labels
Posted by Adrian Groves on Mar-05-2011 01:20
Attachments:
Hi Peter,

In the ChartDirector help, there is an example of a surface chart with a date/time axis
and a
label axis (image attached).

The code is as follows (from the example) :

<?php
require_once("../lib/phpchartdir.php");

# The x and y coordinates of the grid
$dataX = array(chartTime(2008, 9, 1), chartTime(2008, 9, 2), chartTime(2008, 9, 3),
    chartTime(2008, 9, 4), chartTime(2008, 9, 5), chartTime(2008, 9, 6));
$dataY = array("Low", "Medium", "High");

# The data series
$lowData = array(24, 38, 33, 25, 28, 36);
$mediumData = array(49, 42, 34, 47, 53, 50);
$highData = array(44, 51, 38, 33, 47, 42);

# Create a SurfaceChart object of size 760 x 500 pixels
$c = new SurfaceChart(760, 500);

# Add a title to the chart using 18 points Arial font
$c->addTitle("Surface Chart Axis Types", "Arial", 18);

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

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

# Set the data to use to plot the chart. As the y-data are text strings (enumerated),
# we will use an empty array for the y-coordinates. For the z data series, they are
# just the concatenation of the individual data series.
$tmpArrayMath1 = new ArrayMath($lowData);
$tmpArrayMath1->insert($mediumData);
$tmpArrayMath1->insert($highData);
$c->setData($dataX, null, $tmpArrayMath1->result());

# Set the y-axis labels
$c->yAxis->setLabels($dataY);

# Set x-axis tick density to 75 pixels. ChartDirector auto-scaling will use this as
# the guideline when putting ticks on the x-axis.
$c->xAxis->setTickDensity(75);

# Spline interpolate data to a 80 x 40 grid for a smooth surface
$c->setInterpolation(80, 40);

# Set surface grid lines to semi-transparent black (cc000000).
$c->setSurfaceAxisGrid(0xcc000000);

# Set contour lines to the same color as the fill color at the contour level
$c->setContourColor(SameAsMainColor);

# Add a color axis (the legend) in which the top right corner is anchored at (95,
# 100). Set the length to 160 pixels and the labels on the left side.
$cAxis = $c->setColorAxis(95, 100, TopRight, 160, Left);

# Add a bounding box with light grey (eeeeee) background and grey (888888) border.
$cAxis->setBoundingBox(0xeeeeee, 0x888888);

# Set label style to Arial bold for all axes
$c->xAxis->setLabelStyle("arialbd.ttf");
$c->yAxis->setLabelStyle("arialbd.ttf");
$c->zAxis->setLabelStyle("arialbd.ttf");
$c->colorAxis->setLabelStyle("arialbd.ttf");

# Set the x, y and z axis titles using deep blue (000088) 15 points Arial font
$c->xAxis->setTitle("Date/Time Axis", "ariali.ttf", 15, 0x000088);
$c->yAxis->setTitle("Label\\nBased\\nAxis", "ariali.ttf", 15, 0x000088);
$c->zAxis->setTitle("Numeric Axis", "ariali.ttf", 15, 0x000088);

# Output the chart
header("Content-type: image/jpeg");
print($c->makeChart2(JPG));
?>



What I want is to show the same chart, but with the date/time axis being a label axis as
well as the Y-axis ! If I change the array $dataX from a list of dates into a list of strings
(e.g. $dataX = array ('a', 'b', 'c', 'd', 'e', 'f')), the chart does not show any values.

Hope this is clearer,

regards,

Adrian
surface1.jpg

  Re: Surface Chart Labels
Posted by Peter Kwan on Mar-06-2011 15:45
Hi Adrian,

As explained in my previous message, you cannot use axis labels as data values. You would need to use array indexes. For example:

#these are your data values
$dataX = array(0, 1, 2, 3, 4, 5);

#The labels are not data values. They are for human reading only.
$labelsX = array  ('a', 'b', 'c', 'd', 'e', 'f');
$c->xAxis->setLabels($labelsX);

Hope this can help.

Regards
Peter Kwan