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

Message ListMessage List     Post MessagePost Message

  Can't insert a graph into a table cell.
Posted by Mick on Dec-11-2014 22:47
Hello
I have a page of HTML where I want to insert a ChartDirector chart into a table cell. I
am attempting to insert the image into a table cell with <img src =  "newchart.php" />

The chart is created in newchart.php (which is in the same directory as the file with the
<img> tag above) with:
    //new chart 430 x 225
    $c = new XYChart(430, 225);
    $c->setPlotArea(0, 0, 380, 200);

    //add legend
    $legendObj = $c->addLegend(50, 30, true, "arialbd.ttf", 9);
    $legendObj->setBackground(Transparent);
    //title for y axis
    $c->yAxis->setTitle("Value on Loan as % of Market Cap");
    //x axis labels  (months)
    $c->xAxis->setLabels($dateArray);
    //add line layer to chart
    $layer = $c->addLineLayer2();
    //set line width to 2 px
    $layer->setLineWidth(2);
    // Add the data sets to the line layer.
    //index (always displayed)
    $layer->addDataSet($indexArray, 0x0000FF, $nameIndex);
    //stock 1
    if(!empty($stock1Array)){
        $layer->addDataSet($stock1Array, 0x00CCFF, $nameStock1);
    }
    //stock 2
    if(!empty($stock2Array)){
        $layer->addDataSet($stock2Array, 0x000099, $nameStock2);
    }
    //sector
    if(!empty($sectorArray)){
        $layer->addDataSet($sectorArray, 0x999999, $nameSector);
    }
    //Output the chart
    header("Content-type: image/png");
     print($c->makeChart2(PNG));

I have checked the various variables ($indexArray, $stock1Array etc.) and have seen
that they are all appropriately filled.
However, when I look at my page in the browser, all I see is the icon for a corrupt or
missing image. Inspecting the element in the browser, I see:
<td style="padding-left: 70px;" class="noBorder">
   <img src="newchart.php">
</td>
which looks OK to me. So how come I don't get to see the image? Any help gratefully
received. Thanks.

  Re: Can't insert a graph into a table cell.
Posted by Peter Kwan on Dec-11-2014 23:51
Hi Mick,

First, please check if whether your chart can display in an <IMG> tag at all. You may want to check if the following code would work:

<html><body>
<img src="newchart.php">
</body></html>

If you are seeing a broken image symbol, the first thing to do is to go into the broken image symbol to read the error message. You may refer to the following post on how this can be done:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_faq&thread=1117817200

Please kindly let me know what is the error message, or provide me the file that contains the broken X symbol.

Regards
Peter Kwan

  Re: Can't insert a graph into a table cell.
Posted by Mick on Dec-12-2014 01:40
Thank you, Peter.
This seems rather mysterious. When I enter in the address bar the full URL of the file
which generates the chart (newchart.php), I get a 404 error. Entering the full URL of any
other php file in that same directory does not produce a 404 error. I'm on a Windows
machine using an Administrator account, so I assume it's not a permissions problem. I
temporarily renamed newchart.php to newchart_orig.php and then created a blank php file
named newchart.php. Accessing that file by entering the full URL in the address bar did not
cause any problems and returned a 200 from the server. I can't say I've ever come across
this behaviour before, but assume I must have somehow made a mess of the code in my
original newchart.php, so I'll have a good poke around inside that and see what I can
come up with.
-Mick

  Re: Can't insert a graph into a table cell.
Posted by Mick on Dec-12-2014 01:58
Hello, Peter
It transpires that the problem was not with not finding newchart.php, but with not finding a
file specified in a require_once statement. I now get to see a graph with labels on the x-
axis. Nothing else, unfortunately, but I guess I can sort that out.
Thanks for your help.
Mick