簡體   English   中英

如何將Json數據推送到折線圖功能

[英]How to push Json data to line chart function

我使用高圖表創建折線圖,從數據庫中獲取價值,並且需要像下面那樣傳遞這些價值折線圖

//categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] // This is static values
categories: [series]  //Passing value from database

現在我創建了ajax函數來傳遞值

 $.ajax({
                type: "GET",
                url: "/api/ReportAPI/GetMonthlyEmployeeFte",
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (Result) {
                    var data = [];
                    for (var i in Result) {
                    var serie = new Array(Result[i].MONTH);
                    data.push(serie));
                      }
                DreawLineChart(data);
                },
                failure: function (response) {
                    alert(response.responseText);
                },
                error: function (response) {
                    alert(response.responseText);
                }
            });

圖表代碼/功能

function DreawLineChart(series) {
    Highcharts.chart('container2', {
        chart: {
            type: 'line'
        },
        title: {
            text: 'Monthly Employee FTE'
        },
        subtitle: {
            //text: 'Source: WorldClimate.com'
        },
        xAxis: {
            //categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            categories: [series]  //Here i want push data month from ajax
        },     
        yAxis: {
            title: {
                text: 'FTE'
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        series: [{
            name: 'Singapore',
            data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]

        }, {
            name: 'New Zealand',
            data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
    });
}

但是,它在圖表中一點顯示數據,而不是分別顯示1月3月11月12月。

折線圖

不要在series使用方括號。 series已經是一個數組。 僅使用categories: series

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM