0

「スプライン」と「パイ」で構成される ajax json オブジェクトから組み合わせグラフを作成しています。

私が抱えている問題は、円グラフがスプラインを上書きするかのように、円グラフのみがレンダリングされることです。円グラフを削除すると、スプラインが正しくレンダリングされます。

これが私のコードです。

$(document).ready(function () {
var options = {
    chart: {
        renderTo: 'container'
    },
    title: {
        text: 'The Planning Process'
    },
    xAxis: {
        title: {
            text: 'Time'
        },
        type: 'datetime'
    },
    yAxis: {
        title: {
            text: 'Turn Over'
        }
    },
    plotOptions: {
        series: {}
    },
    series: []
};

$.ajax({
    type: "POST",
    dataType: "json",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    url: "_services/ScriptService.asmx/getData",
    success: function (items) {

        var obj = jsonParse(items.d);
        var series = { data: [] };

        $.each(obj, function (itemNo, item) {
            if (itemNo == 0) {
                series.data = item.data;
                series.name = item.name;
                series.type = item.type;
            } else if (itemNo == 1) {
                series.type = item.type;
                series.data = item.data;
           series.name = item.name;
                series.center = item.center;
                series.size = item.size;
                series.showInLegend = item.showInLegend;
            }
        });

        options.series.push(series);

        chart = new Highcharts.Chart(options);
        console.log(options);

    },
    cache: false,
    error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); }
});  
});

そして私のjson;

[{
    "name": "Projection",
    "type": "spline",
    "data": [
        [
            634420512000000000,
            100000
        ],
        [
            634421376000000000,
            100086
        ],
        [
            634422240000000000,
            100171
        ],
        [
            634423104000000000,
            100257
        ]
    ]
},
{
    "name": "Where you where",
    "type": "pie",
    "center": [
        100,
        80
    ],
    "size": 100,
    "showInLegend": false,
    "data": [
        {
            "name": "Client Based Adviser Charged As Percent",
            "color": "#4572A7",
            "y": 8
        },
        {
            "name": "Provider Commission Based As Percent",
            "color": "#AA4643",
            "y": 92
        }
    ]
}]

誰かが私がどこで間違っているのか教えてもらえますか?

4

1 に答える 1

2
success: function (items) {

    var obj = jsonParse(items.d);

    $.each(obj, function (itemNo, item) {
        series = new Array();
        if (itemNo == 0) {
            series.data = item.data;
            series.name = item.name;
            series.type = item.type;
        } else if (itemNo == 1) {
            series.type = item.type;
            series.data = item.data;
            series.name = item.name;
            series.center = item.center;
            series.size = item.size;
            series.showInLegend = item.showInLegend;
        }
        options.series.push(series);
    });

    chart = new Highcharts.Chart(options);
    console.log(options);

},

このループは 2 番目のシリーズを追加することはありません。前のシリーズを上書きしているため、ループ内の最後のシリーズのみを取得しています。

私の変更で問題が解決する可能性があります。確認するために、現在コンピューターの近くにいません。

于 2011-06-06T08:55:03.967 に答える