1

I am using the remote API for the library.

My Data Structure

$graph = new \stdclass;
$graph->width = 500;
$graph->height = 350;
$data1 = array('gross'=>23, 'taxed'=>45, 'discount'=>20, 'revenue'=>32, 'due'=>14);
$data2 = array('gross'=>15, 'taxed'=>23, 'discount'=>23,'revenue'=>12, 'due'=>17);
$data3 = array('gross'=>43, 'taxed'=>23, 'discount'=>34, 'revenue'=>16, 'due'=>20);
$graph->data = array($data1,$data2,$data3);
$graph->setBarColor = array('blue','green','yellow');
$graph->setLegend = 'true';
$graph->setLegendTitle = array('Today','MTD','YTD');
$graph->setTitle = 'Revenue Stats';
$graph->setTitleLocation = 'left';
//JSON encode graph object
$encoded = urlencode(json_encode($graph));
//retrieve XML
$target = 'http://www.ebrueggeman.com/phpgraphlib/api/?g=' . $encoded . '&type=xml';`

ERROR

(2/2) Exception
String could not be parsed as XML
(1/2) ErrorException
SimpleXMLElement::__construct():
Start tag expected, '<' not found

Works fine with a single dataset, but I am unable to load with multiple datasets.

Any Suggestions?

Nitish Patra
  • 289
  • 5
  • 20
  • dump the content returned – delboy1978uk Jun 08 '18 at 10:03
  • @LawrenceCherone $xml_object = new \SimpleXMLElement($target, NULL, TRUE); is after the $target line – Nitish Patra Jun 08 '18 at 10:14
  • Whats the value of `$target`? – Lawrence Cherone Jun 08 '18 at 10:16
  • @LawrenceCherone Are you sure it doesn't support multidimensional data?It says Syntax is different, but similar, to the regular PHPGraphLib library. And the original library does support multi dimensional data. – Nitish Patra Jun 08 '18 at 10:16
  • http://www.ebrueggeman.com/phpgraphlib/api/?g=%7B%22width%22%3A500%2C%22height%22%3A350%2C%22data%22%3A%5B%7B%22gross%22%3A23%2C%22taxed%22%3A45%2C%22discount%22%3A20%2C%22revenue%22%3A32%2C%22due%22%3A14%7D%2C%7B%22gross%22%3A15%2C%22taxed%22%3A23%2C%22discount%22%3A23%2C%22revenue%22%3A12%2C%22due%22%3A17%7D%2C%7B%22gross%22%3A43%2C%22taxed%22%3A23%2C%22discount%22%3A34%2C%22revenue%22%3A16%2C%22due%22%3A20%7D%5D%2C%22setBarColor%22%3A%5B%22blue%22%2C%22green%22%2C%22yellow%22%5D%2C%22setLegend%22%3A%22true%22%2C%22setLegendTitle%22%3A%5B%22Today%22%2C%22MTD%22%2C%22YTD%22%5D%2C%22setTitle – Nitish Patra Jun 08 '18 at 10:17
  • %22%3A%22Revenue+Stats%22%2C%22setTitleLocation%22%3A%22left%22%7D&type=xml – Nitish Patra Jun 08 '18 at 10:18
  • Sorry the link was too lengthy to add in a single line. – Nitish Patra Jun 08 '18 at 10:19

1 Answers1

1

No, the API does not support it, its broken.. a simple check of the URL produces some invalid XML.

$this->data[0],$this->data[1],$this->data[2]<br><br>$graph->addData($this->data[0],$this->data[1],$this->data[2]);<br><?xml version="1.0"?>
<phpgrahphlib>
    <imageName>230_0046831d980a56de52331b09b7eb7efc.png</imageName>
    <imageLocation>http://www.ebrueggeman.com/sites/www.ebrueggeman.com/files/phpgraphlib_api/230_0046831d980a56de52331b09b7eb7efc.png</imageLocation>
    <imageTag><![CDATA[<img width="500" height="350" src="http://www.ebrueggeman.com/sites/www.ebrueggeman.com/files/phpgraphlib_api/230_0046831d980a56de52331b09b7eb7efc.png" />]]></imageTag>
    <error></error>
    <version>2.30</version>
</phpgrahphlib>

But does generate the graph:

enter image description here

So you could attempt to remove everything before <? then just use simplexml_load_string. Might want to report a bug so it's fixed.

<?php
$xml = file_get_contents($target);

$target = strstr($xml, '<?');

$xml_object =  simplexml_load_string($target);

echo 'Image Tag: '. $xml_object->imageTag.PHP_EOL;
echo 'Errors: '. $xml_object->error.PHP_EOL;

https://3v4l.org/abHqm

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106