【问题标题】:Highcharts Column with phpphp的Highcharts专栏
【发布时间】:2016-02-19 04:09:49
【问题描述】:

我遇到了 Highchart 图形的问题。这个 -> http://www.highcharts.com/demo/column-basic

我有一个数据库,其中有一个名为“Days”和“Works”的表,我想将我拥有的日期放在“categories []”和系列中的工作 []; 但 我不知道我的 JSON 需要如何,或者最好的方法是使用 JS 数组

我试过这样:

    js_array = new Array(<?php echo implode(',', $array1); ?>);

 xAxis: {
            categories: js_array,
            crosshair: true
        },

或者只是categories:&lt;?php echo json_encode($array1);?&gt;

但没有成功。

你能帮帮我吗?

【问题讨论】:

    标签: javascript php json ajax highcharts


    【解决方案1】:

    我使用 asp.net (MVC5) 执行此操作,但我认为 php 的想法相同,希望对您有所帮助。

    <script>
    
        $(function () {
            var chart = new Highcharts.Chart({
                chart: {
                    type: 'column',
                    renderTo: 'container'
                },
                title: {
                    text: "Client's downloads"
                },
                subtitle: {
                    text: 'Click the columns to view products.'
                },
                xAxis: {
                    type: 'category'
                },
                yAxis: {
                    title: {
                        text: 'Total downloads'
                    }
                },
                legend: {
                    enabled: false
                },
                plotOptions: {
                    series: {
                        borderWidth: 0,
                        dataLabels: {
                            enabled: true
                        }
                    }
                },
                tooltip: {
                    headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
                    pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}</b><br/>'
                },
                series: [{
                    name: "Downloads",
                    colorByPoint: true,
                    data: [
                        @foreach (var item in Model)
                        {
                                <text>{</text>
                                <text>name: "</text> @item.Name <text>",</text>
                                <text>y: </text> @item.Downloads <text>,</text>
                                <text>drilldown: "</text>@item.Name<text>"},</text>
                        }
                    ]
                }],
                drilldown: {
                    series: [
    
                        @foreach (var item in Model)
                        {
                            <text>{</text>
                            <text>name: "</text>@item.Name<text>",</text>
                            <text>id: "</text>@item.Name<text>",</text>
    
                            <text>data: [</text>
    
                                foreach (var download in item.ProductDownloads)
                                {
                                    <text>["</text> @download.Product <text>", </text> @download.Downloads <text>],</text>
                                }
    
                            <text>]</text>
    
                            <text>},</text>
                        }
    
                        ]
                }
            });
        });
    
    
    </script>
    

    【讨论】:

    • 我的建议是只使用 javascript 代码,然后当它工作时添加你的 php 代码。
    • 谢谢,这有助于理解如何做到这一点的逻辑概念
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 2017-09-29
    • 2015-10-21
    • 2013-09-11
    • 2011-06-15
    • 2011-06-14
    相关资源
    最近更新 更多