var drawChart = function(sourceUrl) { $.ajax({ "type" : "post", "url" : sourceUrl, "success" : function(result) { var data = result.data;//获取数据 var categories = result.categories;//categories类别 var datas = []; //把data数据处理成一条条json的格式的数据,付给series for ( var i = 0; i < data.length; i++) { // 构建折线图数据 datas.push({ name : data[i].name,//线条的名字 data : data[i].data//线条走势所需要的数据 }); }//end for if (datas.length > 0) { var stepSize= Math.floor(categories.length/10); drawLine(datas, categories);//把所需的数据传给highcharts $("#line").css('display','block'); $("#line").show(); } }, "dataType" : "json" }); }; // var chart; var drawLine = function(data, categoriess) { chart = new Highcharts.Chart({ chart : { renderTo : 'line', defaultSeriesType : 'line' }, title : {text : '频道观看时长统计图'}, xAxis : { categories :categoriess, title:{ text:"时间"} }, yAxis : {title : {text : '观看时长'} }, legend: { layout: 'vertical', backgroundColor: '#FFFFFF', align: 'left', verticalAlign: 'top', x: 50, y: 20, floating: true, shadow: true }, series :data }); };