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轴上的值,但没有显示任何内容。有没有人知道为什么被第一个数据集忽略的原因显示正常?
答案 0 :(得分:1)
确保拥有最新的canvasjs文件。