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

Message ListMessage List     Post MessagePost Message

  couldnt display charts
Posted by M_jay on Jan-17-2011 13:10
I have wrote a small php program for display a chart. When I try to view it on my browser it didn't displayed.Page displays  something like below ;

?8?f+??,G??????}K]?=??P?????^????i?u?m??q?E??J?u?8}S?P 82??? ?Q?|Z???f*?lU?:PoJ?mS\\e?????:z>?*??F??K?kjV??????y??y?1K4????I*?|?4v?!? ?o}???m Ny?*????^??Bz??)Eq??[?? ?F?Ob?\\nMm?1???!?^?6?p?u?!?O?C?????'?*???'?!?*7??W??? k7{??^? 6]#??\\???/?]??E?t??iV??p:?E?9????eX?)????L?b>m???A??z?u?W??*;n~!???-S?5????Zj?E?? ?a 4?N????W?Z??j1o?)D?`??U?|-?b%??k???b???X??%??PM???*??O?R?sj*2????C?8?Y.?gi?)?}????{???Q?????�o???L???N?N?!Y?:?? ?J?


This is my php code

*******************
<?php

require_once("C:/xampp/php/ext/phpchartdir.php");

$con = mysql_connect("localhost:3306","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("mygraphs", $con);

  $result1 = mysql_query("SELECT Rating_State FROM rating_state_and_federal Where Year='2010' ");
$array= $result;


$result2 = mysql_query("SELECT Rating_Federal FROM rating_state_and_federal Where Year='2010' ");
$array = $result;




$labels = array("Jan10", "Feb10", "Mar10", "Apr10", "May10", "Jun10", "Jul10", "Aug10", "Sep10", "Oct10", "Nov10", "Dec10");

$c = new XYChart(600, 375);

$c->addTitle("Overall Satisfaction", "timesbi.ttf", 18);


$c->setPlotArea(50, 55, 500, 280, $c->linearGradientColor(0, 55, 0, 335, 0xf9fcff, 0xaaccff), -1, Transparent, 0xffffff);

$legendObj = $c->addLegend(50, 28, false, "arialbd.ttf", 10);
$legendObj->setBackground(Transparent);

$c->xAxis->setLabels($labels);

$c->yAxis->setTickDensity(30);

$c->xAxis->setLabelStyle("arialbd.ttf", 8);
$c->yAxis->setLabelStyle("arialbd.ttf", 8);

# Set axis line width to 2 pixels
$c->xAxis->setWidth(2);
  $c->yAxis->setWidth(2);

# Add axis title using 10pts Arial Bold Italic font
$c->yAxis->setTitle("Satisfaction Score(1 Very bad - 5 Very good)", "arialbi.ttf", 10);

# Add a line layer to the chart
$layer = $c->addLineLayer2();
  # Set the line width to 3 pixels
   $layer->setLineWidth(3);

   # Add the three data sets to the line layer, using circles, diamands and X shapes as
    # symbols

  $dataSetObj = $layer->addDataSet($result1, 0x00ff00, "State Government");
   $dataSetObj->setDataSymbol(DiamondSymbol, 11);
   $dataSetObj = $layer->addDataSet($result2, 0xff6600, "Federal Government");
    $dataSetObj->setDataSymbol(DiamondSymbol, 11);

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


please help me.

  Re: couldnt display charts
Posted by Peter Kwan on Jan-17-2011 21:05
Hi M_jay,

The error is because your code outputs both HTML/Text and the chart image. According to HTML standard, it is illegal to include any image in HTML. You can only include an <IMG> tag in HTML to reference the image. (If you look at the HTML source of any web page, you should not find any image at all, only <IMG> tags.)

For your case, have you also included HTML in the same PHP file? Note that in PHP, everything that is not in <?php .... ?> is treated as HTML. Even an empty line or empty space is HTML. Have you included empty lines or empty space before the <?php ... ?> block? Also, if your code creates any text output (such as using echo or print statements to print text, or if your code results in any warning or notification messages), it will be treated as HTML. Finally, it seems you have commented out the line 'header("Content-type: image/png");'. Please do not comment it out. This line is needed to tell the browser that the file is an image, and not HTML.

The chart image can be referenced in HTML just like another other image - by using an <IMG> tag. For example:

<HTML><BODY> Hello World <BR /> <IMG SRC="createMyChart.php"> </BODY></HTML>

In the above, "createMyChart.php" is a PHP script that creates the chart. The "createMyChart.php" should just contain the chart. It must not contain any HTML. Similarly, the HTML must not contain the chart, but just an <IMG> tag to reference the chart.

If the above still cannot solve the problem, would you mind to attach the exact PHP file that you are using? (Please do not just copy and paste the code. I need to exact PHP file to check for empty space and empty lines in the file.) If you cannot post the PHP file in a public forum, you may email me at pkwan@advsofteng.net

Hope this can help.

Regards
Peter Kwan