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

Message ListMessage List     Post MessagePost Message

  Error BaseChart.getWidth
Posted by poe on Dec-18-2010 04:24
Hi Peter,
I try to run the Binary Data Series Chart but i get this error:
Fatal error: unknown method BaseChart.getWidth in
C:\\xampp\\htdocs\\greenhvac\\demosite\\charts\\lib\\phpchartdir.php on line 1138
I update the hole lib folder with the latest.
I also find that chartdirr.dll can cause the same issue.
Mi chartdir.dll file is 2.20MB (vs 1.73MB the old ) and phpchartdir.php is 124.86Kb (vs.
111.02Kb the old).
I mention that $dataY and $dataX are arrays with 450 elements.
Thanks
Mircea
Here is the code:
<?php
require_once("lib/phpchartdir.php"); // pentru grafic

if (isset($_GET["start_date"]))
    $selected_start_data = $_GET["start_date"];
else
   $selected_start_data = "2010-11-02"; //data asta este luata din 1BW fisier  adica data
curenta nu cred ca trebuie linia asta de cod

if (isset($_GET["FC"]))
    $selected_FC = $_GET["FC"];
else
   $selected_FC = "1";


$StartDate = $selected_start_data;
$selected_An=substr($StartDate, 0, 4);
$selected_Luna=substr($StartDate, 5, 2);
$selected_Zi=substr($StartDate, 8, 2);

$date= $selected_An."/".$selected_Luna."/".$selected_Zi; //$date = '2007/08/30' asa
trebuie sa fie formatul

$weekday_as_text = date('l', strtotime($date)); // am nevoie cind scriu ziua in grafic

$selected_day_charttime_start = chartTime($selected_An, $selected_Luna, $selected_Zi,
00, 00, 00 );

$selected_day_charttime_end = chartTime($selected_An, $selected_Luna, $selected_Zi,
59, 59, 59 );

$mysqli = new mysqli('localhost','root','')or die(mysql_error());
$mysqli->select_db('demosite')or die(mysql_error());
$tabel_db = "demo" ;

$res = $mysqli->query("SELECT TIMPULGRAFIC,A3 FROM $tabel_db WHERE
TIMPULGRAFIC BETWEEN " . $selected_day_charttime_start . " AND " .
$selected_day_charttime_end . " Order By TIMPULGRAFIC ");

// sa adaugi o linie la grafic


while ($row = mysqli_fetch_row($res)) {

$timeStamps []= $row[0];    // TIMPUL - TIMPUL GRAFIC

    $dataSeriesA []= $row[1];   // RUN AMPS - A3

}

//foreach ($ora_1 as &$value)  {if($value ==1.7E+308){$value=NULL;}else {($value=
($value-32)*5/9);}}
//unset($value); // break the reference with the last element

foreach ($dataSeriesA as &$value)  {if($value > 2 ){$value=1;}else { $value= 0;}}
unset($value); // break the reference with the last element

//print_r ($timeStamps);
//echo  "<br>";
//echo  "<br>";
//echo  "<br>";
//print_r ($dataSeriesA);

///// G R A F I C U L /////////////////////////////////////////////////

# The data for the chart
$dataY = $dataSeriesA;
$dataX = $timeStamps;

# In this example, we only use position 1, 3, 5 for the data series. Positions 0, 2,
# 4, 6 are empty and serve as gaps.
$labels = array("", "ON Only Filling", "",
    "<*font,color=cc2200*>ON<*/font*> / <*font,color=00aa22*>OFF<*/font*> Filling",
    "", "Logic Line", "");

# Create a XYChart object of size 600 x 180 pixels
$c = new XYChart(600, 180);

# Add a title to the chart using 10 points Arial Bold font. Set top/bottom margins to
# 12 pixels.
$title = $c->addTitle("Binary Data Series Demonstration", "arialbd.ttf", 10);

# Tentatively set the plotarea at (100, 30) and of size 470 x 120 pixels. Use
# transparent border. Use grey (888888) solid line and light grey (ccccc) dotted line
# as major and minor vertical grid lines.
$plotAreaObj = $c->setPlotArea(100, 30, 470, 120, -1, -1, Transparent);
$plotAreaObj->setGridColor(Transparent, 0x888888, Transparent, $c->dashLineColor(
    0xcccccc, DotLine));

# Set axes to transparent
$c->xAxis->setColors(Transparent);
$c->yAxis->setColors(Transparent);

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

# Set y-axis label style to 8pts Arial Bold
$c->yAxis->setLabelStyle("arialbd.ttf", 8);

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

# Use "<*font=Arial Bold*>{value|mmm dd}" for the first label of an hour, and
# "{value|hh:nn}" for all other labels.
$c->xAxis->setMultiFormat(StartOfDayFilter(), "<*font=arialbd.ttf*>{value|mmm dd}",
    AllPassFilter(), "{value|hh:nn}");

#
# A Logic Line can be achieved using a StepLineLayer in ChartDirector
#

# Shift the data by 4.5, so instead of 0 - 1, it is now 4.5 to 5.5, or fluctuate
# around the y = 5 (Logic Line label) position.
$tmpArrayMath1 = new ArrayMath($dataY);
$tmpArrayMath1->add(4.5);
$shiftedLine0 = $tmpArrayMath1->result();

# Add step lines using the original and the reversed data
$layer0 = $c->addStepLineLayer($shiftedLine0, 255);
$layer0->setXData($dataX);

#
# To perform ON/OFF filling, we draw the logic line, and its reverse, and fill the
# region in between
#

# Shift the data by 2.5, so instead of 0 - 1, it is now 2.5 to 3.5, or fluctuate
# around the y = 3 (ON/OFF Filing label) position.
$tmpArrayMath1 = new ArrayMath($dataY);
$tmpArrayMath1->add(2.5);
$shiftedLine1 = $tmpArrayMath1->result();
# Reverse the data, so the 0 becomes 1 and 1 becomes 0, and shift it as well.
$tmpArrayMath1 = new ArrayMath($dataY);
$tmpArrayMath1->mul(-1);
$tmpArrayMath1->add(3.5);
$reverseShiftedLine1 = $tmpArrayMath1->result();

# Add step lines using the original and the reversed data
$layer1 = $c->addStepLineLayer($shiftedLine1, Transparent);
$layer1->addDataSet($reverseShiftedLine1, Transparent);
$layer1->setXData($dataX);

# Fill the region between the two step lines with green (00aa22) or red (cc2200),
# depending on whether the original or the reserve is higher.
$c->addInterLineLayer($layer1->getLine(0), $layer1->getLine(1), 0x00aa22, 0xcc2200);

#
# The ON Only filling is the same as ON/OFF filling, except the OFF filling color is
# transparent
#

# Shift the data by 0.5, so instead of 0 - 1, it is now 0.5 to 1.5, or fluctuate
# around the y = 1 (ON Only Filing label) position.
$tmpArrayMath1 = new ArrayMath($dataY);
$tmpArrayMath1->add(0.5);
$shiftedLine2 = $tmpArrayMath1->result();
# Reverse the data, so the 0 becomes 1 and 1 becomes 0, and shift it as well.
$tmpArrayMath1 = new ArrayMath($dataY);
$tmpArrayMath1->mul(-1);
$tmpArrayMath1->add(1.5);
$reverseShiftedLine2 = $tmpArrayMath1->result();

# Add step lines using the original and the reversed data
$layer2 = $c->addStepLineLayer($shiftedLine2, Transparent);
$layer2->addDataSet($reverseShiftedLine2, Transparent);
$layer2->setXData($dataX);

# Fill the region between the two step lines with green (00aa22) or transparent,
# depending on whether the original or the reserve is higher.
$c->addInterLineLayer($layer2->getLine(0), $layer2->getLine(1), 0x00aa22, Transparent
    );

# Adjust the plot area size, such that the bounding box (inclusive of axes) is 10
# pixels from the left edge, 10 pixels  below the title, 30 pixels from the right
# edge, and 10 pixels above the bottom edge.
$c->packPlotArea(10, $title->getHeight() + 10, $c->getWidth() - 30, $c->getHeight() -
    10);

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








?>

  Re: Error BaseChart.getWidth
Posted by Peter Kwan on Dec-18-2010 17:35
Hi poe,

Please try the original unmodified Binary Data Series sample code that comes with ChartDirector. If the same error occurs, it may be because your code is using an older version of ChartDirector.

To confirm exactly which version of ChartDirector you are using, please use the "ChartDirector/phpdemo/cdinfo.php" that comes with ChartDirector. It will display the ChartDirector version, and also exactly where is the active "chartdir.dll".

(Note: cdinfo.php assumes the ChartDirector library is in "../lib/phpchartdir.php". You may need to modify it to fit your directory structure.)

It is common for people to copy the files in "ChartDirector/lib" to many other directories on the server. So there may be multiple copies of "chartdir.dll" and "phpchartdir.php" in your web site. If you are upgrading from an older verison of ChartDirector, it is possible that some of the DLL copies are not updated, and the PHP happens to be using the non-updated DLL.

Also, depending on how your PHP system is configured, you may need to restart the web server for the updated DLL to take effect. (From my understand of xampp on Windows, you may be unable to update the DLL at all, as Windows may complain that the file is locked by another process. If you can update the DLL freely at any time, may be the server is not using that copy of the DLL at all.)

Regards
Peter Kwan

  Re: Error BaseChart.getWidth
Posted by Mircea on Dec-18-2010 19:29

Thanks Peter,
It works fine.

Can you suggest me a way how I can calculate the total time ON and total time OFF ?

Thanks again
Mircea

  Re: Error BaseChart.getWidth
Posted by Peter Kwan on Dec-19-2010 14:10
Hi Mircea,

To calculate the total time ON, you may add all the ON time together. To calculate the total time OFF, you may add all the OFF time together. (You do not need to use ChartDirector to compute or add the time together.)

Hope this can help.

Regards
Peter Kwan