Colour
Colour may be manually
added for a point when adding the point.
Example
$tChart1->addSeries(new Bar());
$tChart1->getSeries(0)->addYTextColor(50,"oranges", Color::ORANGE());
Alternatively, you can
allow TeeChart to allocate a colour. TeeChart will choose one of up to 19
unique and as yet unused colours for each new Series, or for each new Series
point if ColorEach is set to true.
Example
$tChart1->getSeries(0)->setColorEach(true);
for($i = 0; $i < 19; ++$i) {
$higher = $i + 65;
$tChart1->getSeries(0)->add(rand(0,100));
}
Use Series.Delete to delete a point from a Series.
Example
$tChart1->getSeries(0)->delete(7);
//(8th point - Points index start at zero)
Series->Clear clears all points from a Series.
See the table Adding
data to a Series
for a list of Series Types that support the AddNull method. As the name
suggests, AddNull will add a Null point to the Series allowing you to define a
label for the point but leaving a break in the Series at that point. In the
case of a Line Series, the last point before the break will not join to the
first point after the break. See Series->AddNull.
example
$line = new Line($tChart1->getChart());
$line->addNull();
TeeChart Pro offers an
empty Chart Canvas as a backdrop to data Series. That means that no Chart types
are predefined. You define the Chart type you require as a mix of the Series Types
that you wish to display. Due to the specialised nature of some Series types it
is impractical to mix a few of the Series types together on a Chart. TeeChart
helps you by greying out unsuitable Series types in the Chart Gallery when you
arrive to add a new Series. There is no practical limit to the number of Series
that you can put in one Chart.
Add a Series using the
Chart Editor (see Tutorial 1) or by code.
Example
$bar1 = new Bar($tChart1->getChart());
$bar1->fillSampleValues(10);
Series added to the Chart
will automatically take the Left and Bottom axes as their reference axes. You
may change the reference axes, there are 4 axes available, Top, Left,
Bottom and Right. By code, changing the axes will look like this:
$bar1->setHorizontalAxis(HorizontalAxis::$TOP);
$bar1->setVerticalAxis(VerticalAxis::$RIGHT);
More than 1 Series may be
associated with each Axis. TeeChart will decide the best scale to fit the
Series matched to the Axis but you may change Axis scales yourself (See the Axis
Tutorial). Additional
axes may be added, they will copy the scales associated with their counterparts
from the first 4 axes (see the Tutorial section Additional axes).
You may use a Series as the
datasource for another Series. To do it by code see below:
$bar1 = new Bar($tChart1->getChart());
$bar1->fillSampleValues();
$line1 = new Line($tChart1->getChart());
$average1 = new Average();
$line1->setFunction($average1);
$line1->setDataSource($bar1);
$line1->checkDataSource();
See tutorial
7 - Working with Functions for more information about how to use TeeChart functions.
Changing series order is
very easy. Series order will decide the
relative display position of the Series in the Chart with respect to other
Series. Use the SeriesList property or the ExchangeSeries method.
Example
$tChart1->exchangeSeries(0,1); //Change Series(0) with Series(1) in the index order
*Note. After exchanging Series, the index
for the Series will be changed. Thus the line of code above will perpetually
interchange the 2 Series '0' and '1' if the code is rerun, as 0 becomes 1 and 1
becomes 0.
Setting a Series to
'Active=False' will hide the Series from the Chart but maintain its data
content intact.
TeeChart Series store their
values in a Valuelist accessible and modifiable via the TChartValueList component.
This code modifies the
value of a BarSeries Bar according to the user's mouseclick.
Example
upDatePoint($valueIndex,$tChart1->getAxes()->getLeft()->calcPosPoint($e->Y));
Call the UpdatePoint Sub
routine to modify the Bar's value:
private function upDatePoint($bar, $Y)
{
if($bar < $tChart1->getSeries(0)->getCount())
{
$tChart1->getSeries(0)->getYValues()->setValue($bar,Y);
}
}
The previous section
introduces some use of Series events. This section shows some additional uses.
OnGetAxisLabel
In the case we want to change or add extra text to some or all of the axis
labels, the OnGetAxisLabel event must be used, it allows to get the LabelText
which is going to be displayed and modify it if required.
Here we can see
an example of use :
<?php
//Includes
include "../../../sources/TChart.php";
function handleLoad($sender, $args)
{
// print 'object '.get_class($sender).' loaded with '.count($args).' args!<br
/>';
$sender->getHeader()->setText("OnLoad Event");
}
function handleUnLoad($sender, $args)
{
?><br><br><?php
print 'object '.get_class($sender).' unloaded with '.count($args).' args!<br
/>';
?></br><?php
}
// Args contains axis, index order to be displayed, labelText
function handleGetAxisLabel($sender, $args)
{
// If it's going to display left axis labels
if ($args[0] === $sender->getAxes()->getLeft())
{
// if the left axis label value is bigger than 50 add extra character
if ((int)$args[2] > 50) {
$args[0]->getLabels()->labelText = $args[2].'-e';
}
}
else
{
if ($args[0] === $sender->getAxes()->getBottom())
{
if ((int)$args[2] < 4) {
// if value is less than 5 changes its labeltext
$args[0]->getLabels()->labelText = $args[2].'-u';
}
}
}
}
$handlers = new EventHandlerCollection();
$handlers->add(new EventHandler(new ChartEvent('OnLoad'),'handleLoad'));
$handlers->add(new EventHandler(new ChartEvent('OnUnload'),'handleUnload'));
$handlers->add(new EventHandler(new ChartEvent('OnGetAxisLabel'),'handleGetAxisLabel'));
$chart = new TChart(500,300, $handlers);
$chart->getAspect()->setView3D(false);
$points = new Points($chart->getChart());
$chart->addSeries($points);
$points->fillSampleValues();
$points->getPointer()->setHorizSize(10);
$points->getPointer()->setVertSize(5);
$points->setColorEach(true);
//$chart->getLegend()->getSymbol()->setWidth(10);
$chart->getLegend()->getSymbol()->setSquared(false);
$chart->render('chart.png');
$rand=rand();
print '<font face="Verdana" size="2">This Demo shows how to use the OnLoad,
OnUnload and OnGetAxisLabel Events<p>';
print '<img src="chart.png?rand='.$rand.'">';
?>
© 1996-2010 Steema Software SL. All rights reserved.