代码:
$('.subjctList_sbjctWisePrfrmnce').live('click',function(){
$("#main-content").empty();
$("#main-content").append(
"<div class='tab-pane padding-bottom30 active fade in'>"+
"<div id='chartContainer' style='height: 300px; width: 100%;'>"+
"</div>"+
"</div>"
);
var fa1=$(this).attr('data-fa1');
var fa2=$(this).attr('data-fa2');
var term1totalFA=$(this).attr('data-totalfa1');
var sa1=$(this).attr('data-sa1');
var term1Total=$(this).attr('data-trm1gtotal');
var fa3=$(this).attr('data-fa3');
var fa4=$(this).attr('data-fa4');
var term2totalFA=$(this).attr('data-totalfa2');
var sa2=$(this).attr('data-sa2');
var term2Total=$(this).attr('data-trm2gtotal');
var grandTotal=$(this).attr('data-anualtotal');
//在这些变量中获取动态值,如fa1,fa2等
当我们在dataPoints
数组中传递这些值时,我们无法正确创建图形。
而当我们在同一个变量中传递静态值时,它工作正常。
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme2",//theme1
title:{
text: "Basic Column Chart - CanvasJS"
},
animationEnabled: false, // change to true
data: [
{
// Change type to "bar", "splineArea", "area", "spline", "pie",etc.
type: "column",
dataPoints: [
{ label: "FA1", y: fa1 },
{ label: "FA2", y: 15 },
{ label: "SA1", y: 25 },
{ label: "Total Fa1", y: 30 },
{ label: "Term1 Total", y: 28 }
]
}
]
});
chart.render();
}