1

renderを使用して複数の折れ線グラフを作成しようとしてcanvasJSいますが、期待どおりに機能していません。

ここに私の drawChart 関数があります

function drawChart(obj, placeholder){
var dataPoints = [];
var maxPrice = [];
var minPrice = [];
//console.info(obj);
for (var i = obj.length - 1; i >= 0; i--) {
    dataPoints.push({label:obj[i].year+"-"+obj[i].month+"-"+obj[i].day,y:Math.round(obj[i].avgPrice * 1000) / 1000});
    minPrice.push({label:obj[i].year+"-"+obj[i].month+"-"+obj[i].day,y:obj[i].minPrice});
    maxPrice.push({label:obj[i].year+"-"+obj[i].month+"-"+obj[i].day,y:obj[i].maxPrice});
}
console.log(dataPoints);
console.log(maxPrice);
console.log(minPrice);
var chart = new CanvasJS.Chart("chartContainer",
{
    animationEnabled: true,
    //theme: "theme1",
    zoomEnabled: true,
    title:{
        text: placeholder
    },
    data: [
        {
            type: "spline",  //change type to bar, line, area, pie, etc
            showInLegend: true,
            legendText: "Average Price", 
            dataPoints: dataPoints    //this line I tried to change
        },
        {
            type: "spline",  
            showInLegend: true,
            legendText: "Min Price", 
            dataPoints: minPrice
        },
        {
            type: "spline",  
            showInLegend: true,
            legendText: "Max Price", 
            dataPoints: maxPrice
        }
    ],
    legend: {
        cursor: "pointer",
        itemclick: function (e) {
            if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
                e.dataSeries.visible = false;
            } else {
                e.dataSeries.visible = true;
        }
        chart.render();
        }
    }
});

chart.render();

}

var dataPoints, maxPrice, minPrice同じレイアウト/データを持っています。

ここを見て。ここに画像の説明を入力

このようにチャートを表示していますが、2行のリセットminPrice and maxPriceが消えています。

ここに画像の説明を入力

PSに変更dataPoints: dataPointsdataPoints: min/maxPriceても、そのようには機能しません。

4

1 に答える 1