Canvasjs - 缺少轴编号和第二个数据集图例

时间:2018-04-23 23:34:53

标签: jquery html5 canvas canvasjs

https://jsfiddle.net/ma0s5d7x/

jQuery(document).ready(function($) {
var twoPoints = [];
var tenPoints = [];
jQuery.getJSON("https://www.quandl.com/api/v3/datasets/USTREASURY/YIELD.json?api_key=XXXX&collapse=weekly", function(results) {  
    $.each(results.dataset.data, function(key, value){
        twoPoints.push({x: new Date(value[0]), y: parseFloat(value[5])});
        tenPoints.push({x: new Date(value[0]), y: parseFloat(value[9])});
    });
    var chart = new CanvasJS.Chart("chartContainer",{
        title:{
            text:"Treasurey Yield Curve Rates"
        },
        axisX:{
            valueFormatString: "YYYY",
            interval: 2
        },
        axisY: {
            title: "Rate"
        },
        toolTip: {
            shared: true
        },
        data: [{
            name: "2YR",
                showInLegend: true,
            legendText: "2YR",
            type: "line",
            xValueFormatString: "YYYY-MM-DD",
            dataPoints : twoPoints
        },
        {
            name: "10YR",
                showInLegend: true,
            legendText: "10YR",
            type: "line",
            xValueFormatString: "YYYY-MM-DD",
            dataPoints : tenPoints
        }]
    });
    chart.render();
});

});

我已将我的图例和数据集设置为在图例中显示,并且还显示x轴上的值,但没有显示任何内容。有没有人知道为什么被第一个数据集忽略的原因显示正常?

1 个答案:

答案 0 :(得分:1)

确保拥有最新的canvasjs文件。