【问题标题】:Fusionchart , XML , render faultFusionchart , XML , 渲染 错误
【发布时间】: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


【解决方案1】:

如果您想将 text/html 输出与 XML 混合,那么您需要自己格式化 XML 并对其进行 HTML 编码,这样浏览器就不会尝试解释标签。

首先,您需要了解您在那里使用的标头类型,以便输出应采用该格式。

例子:

header("Content-Type: text/xml;"); //gives the output in xml format

header("Content-Type: text/php;"); //gives the output in php format

header("Content-Type: text/html;"); //gives the output in html format

我已经使用了你的代码,解决了你遇到的问题,只是要查看 html 格式的输出,你必须使用header("Content-Type: text/html;");

问题已解决,但您的数据不足以获取图表,因此通过使用足够的数据您将能够看到您想要的图表。

【讨论】:

    猜你喜欢
    • 2021-04-04
    • 2016-06-25
    • 1970-01-01
    • 2013-04-16
    • 2014-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多