首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CanvasJS和PHP

CanvasJS和PHP
EN

Stack Overflow用户
提问于 2017-09-01 14:56:45
回答 1查看 196关注 0票数 0

我想用CanvasJS创建两个图表,其中我使用了php文件中的值。我有两个图表,但只有一个呈现,第二个只有白色背景和标题文本。下面是带值的php代码:

代码语言:javascript
复制
 <?php
require 'excCon.php';
$dataPoints = array(
    array("y" => $excel_result, "label" => "Quantity"),
    array("y" => $excel_result2, "label" => "Value"),
    );

$dataP = array(
    array("y" => $excel_result3, "name" => "1", "exploded" => false),
    array("y" => $excel_result4, "name" => "2"),
    array("y" => $excel_result5, "name" => "3&5"),
    array("y" => $excel_result6, "name" => "4"),
    );
?>

和javascript:

代码语言:javascript
复制
<div id="chartContainer style="height: 400px;width: 80%"">
                <script type="text/javascript">
                    $(function () {
                        var chart1 = new CanvasJS.Chart("chartContainer", {
                            theme: "theme2",
                            animationEnabled: true,
                            title: {
                                text: "Sum"
                            },
                            data: [
                                {
                                    type: "column",
                                    dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
                                }
                        ]
                        });
                        chart1.render();
                    });
                </script>
            </div>
            <div id="chartContainer2" style="height: 400px;width: 80%">
                <script type="text/javascript">
                    $(function () {
                        var chart2 = new CanvasJS.Chart("chartContainer2",
                            {
                                theme: "theme2",
                                title:{
                                    text: "All"
                                },
                                exportFileName: "All",
                                exportEnabled: false,
                                animationEnabled: false,
                                data: [
                                    {
                                        type: "pie",
                                        showInLegend: true,
                                        toolTipContent: "{name}: <strong>{y}%</strong>",
                                        indexLabel: "{name} {y}%",
                                        dataP: <?php echo json_encode($dataP, JSON_NUMERIC_CHECK); ?>
                                    }]
                            });
                        chart2.render();
                    });
                </script>
            </div>

整个代码都在index.php文件中。

根据记录,我在这里以及官方页面上搜索了其他解决方案,都没有成功。

EN

回答 1

Stack Overflow用户

发布于 2017-09-01 15:32:32

解决方案是在数据中包含dataPoints,并且不对其进行更改

代码语言:javascript
复制
data: [
{
type: "column",
**dataPoints** : <?php echo json_encode($dataP, JSON_NUMERIC_CHECK); ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45994810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档