【发布时间】:2015-11-23 22:36:44
【问题描述】:
我有以下脚本,它创建一个 XML 字符串以使用 Fusionchart 呈现图表
<?php
include("includes/fusioncharts.php");
$chart = new SimpleXMLElement("<chart></chart>");
$chart->addAttribute('caption', 'testgrafiek');
$chart->addAttribute('subcaption', 'onderlabel');
$chart->addAttribute('xaxisname', 'naam');
$chart->addAttribute('yaxisname', 'aantal ronden');
$categories = $chart->addChild('categories');
$category[0] = $categories->addChild('category');
$category[1] = $categories->addChild('category');
$category[0] ->addAttribute('label', 'alias1');
$category[1]->addAttribute('label', 'alias2');
$dataset1 = $chart->addChild('dataset');
$dataset1->addAttribute('seriesname', 'Revenues');
$dataset1det[0] = $dataset1->addChild('set');
$dataset1det[0] ->addAttribute('value', '16000');
$dataset1det[1] = $dataset1->addChild('set');
$dataset1det[1] ->addAttribute('value', '18000');
$dataset2 = $chart->addChild('dataset');
$dataset2->addAttribute('seriesname', 'Profits');
$dataset2->addAttribute('renderas', 'line');
$dataset2det[0] = $dataset2->addChild('set');
$dataset2det[0] ->addAttribute('value', '1000');
$dataset2det[1] = $dataset2->addChild('set');
$dataset2det[1] ->addAttribute('value', '8000');
$columnChart = new FusionCharts("column3D", "myFirstChart" , 700, 400, "chart-1", "xml", $chart);
$columnChart->render();
Header('Content-type: text/xml');
echo $chart->asXML();
?>
<div id="chart-1"><!-- Fusion Charts will render here--></div>
如果我运行上面的代码,页面上会出现错误
This page contains the following errors:
error on line 7 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
如果我没有运行代码
$columnChart = new FusionCharts("column3D", "myFirstChart" , 700, 400, "chart-1", "xml", $chart);
$columnChart->render();
和
我在页面上没有错误,并且看到了正确的 XML。
不知道如何解决这个问题。
有人吗?
【问题讨论】:
-
检查你生成的xml。
标签: php simplexml fusioncharts