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

Message ListMessage List     Post MessagePost Message

  Change LineLayer
Posted by giase on Mar-28-2012 17:23
Hi,
how can I change the data series after creating a graph?

<?php
$c = new XYChart(500, 300);
$c->setPlotArea(30, 20, 450, 250);
$c->xAxis->setLabels($arrayResult['time']);

//chart 1
$c->addLineLayer($arrayResult['y1'], 0xff0000, "y1");
$chartInBinary = $c->makeChart2(PNG);
$chartInBase64 = base64_encode($chartInBinary);
echo '<img id="img-a" src="data:image/png;base64,' . $chartInBase64.'" />';

//chart 2
$c->addLineLayer($arrayResult['y2'], 0x0000ff, "y2");
$chartInBinary = $c->makeChart2(PNG);
$chartInBase64 = base64_encode($chartInBinary);
echo '<img id="img-b" src="data:image/png;base64,' . $chartInBase64.'" />';
?>

This produces two times the same chart.
can anyone help me?

  Re: Change LineLayer
Posted by Peter Kwan on Mar-28-2012 23:58
Hi giase,

Unluckily, once a chart is "make" (eg. using makeChart2), it cannot be changed. So in your case, you would need to restructure your code to use a subroutine. It is like:

<?php

function makeMyChart($myData, $myColor, $myName)
{
     $c = new XYChart(500, 300);
     $c->setPlotArea(30, 20, 450, 250);
     $c->xAxis->setLabels($arrayResult['time']);

     //chart 1
     $c->addLineLayer($myData, $myColor, $myName);
     $chartInBinary = $c->makeChart2(PNG);
     $chartInBase64 = base64_encode($chartInBinary);
     echo '<img id="img-a" src="data:image/png;base64,' . $chartInBase64.'" />';
}

makeMyChart($arrayResult['y1'], 0xff0000, "y1");
makeMyChart($arrayResult['y2'], 0x0000ff, "y2");

?>

Note that recreating the XYChart object has no performance impact. It is because the code to create and set up the XYChart requires negligble amount of CPU comparing to "making" the chart. In any case (whether you recreate the XYChart or not), the code still need to call makeChart2 twice, so the CPU consumption is basically the same. Using a subroutine in many case can make the code simplier, as you do not need to repeat the code that calls "makeChart" (and the related base64_encode and data:image/png output method in your case).

Hope this can help.

Regards
Peter Kwan

  Re: Change LineLayer
Posted by giase on Mar-29-2012 14:12
Many many thanks Peter!!!! You have been very clear.
Regards,
giase