php - 无法向 PHPGraphLib 的远程 API 添加和呈现多集数据
问题描述
我正在为库使用远程 API。
我的数据结构
$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';`
错误
(2/2) Exception
String could not be parsed as XML
(1/2) ErrorException
SimpleXMLElement::__construct():
Start tag expected, '<' not found
使用单个数据集可以正常工作,但我无法加载多个数据集。
有什么建议么?
解决方案
不,API 不支持它,它坏了.. 对URL的简单检查会产生一些无效的 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>
但确实会生成图表:
因此,您可以尝试在<?
使用simplexml_load_string之前删除所有内容。可能想报告一个错误,以便修复它。
<?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;
推荐阅读
- python - 如何建立抛硬币三次的贝叶斯模拟模型
- hive - 用于 hive-hbase 集成的 Hive 列的复合键
- php - 通过 api 添加带有 child_attachments 的 Facebook 帖子时出现“无法使用 URL”错误
- firefox - vuetify 设置后在 Firefox 上显示空白页
- javascript - 字符串转换为整数
- mysql - 从mysql中的unix格式转换后比较两个日期
- spring-boot - 无法解析“javax.persistence.EntityManager”的 bean
- sparql - GraphDB Free 8.8 Sparql INSERT 返回 400。不支持 INSERT?
- node.js - 如何使用 azure bot 框架向 Skype 组发送通知消息?
- sas - 折叠大型数据集,同时有条件地保留一些缺失值