首页 新闻 搜索 专区 学院

怎样灵活取值,这样子,每添加一个json的值自己就好手动的去添加好麻烦?求大神指点

0
悬赏园豆:15 [已解决问题] 解决于 2017-04-24 16:52

改变前的js。
$(document).ready(function() {
var sum=[
//=============================CA
{"Flight":"AC","name":"CANPEK","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1797.25,1179.5,1180,1303.33,960]},
{"Flight":"AC","name":"PEKCAN","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1810,1716.67,1403.33,1424.33,1192]},
{"Flight":"AC","name":"CANSHA","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1083.69,1103.14,837,967,1097]},
{"Flight":"AC","name":"PEKSHA","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1176.73,1158.44,1150.53,1124.45,1501.25]},
{"Flight":"AC","name":"SHACAN","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1023.36,926.14,1075,822.5,890]},
{"Flight":"AC","name":"SHAPEK","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1108.9,1103.98,1117.38,1117.55,1045.64]},
{"Flight":"AC","name":"SHASZX","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[980,986.67,993.33,1076.5,840]},
{"Flight":"AC","name":"SZXSHA","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1260,1050,793.33,956.67,1120]},
{"Flight":"AC","name":"SZXPEK","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1918.44,1871.54,1786,1601.67,1662.5]},
{"Flight":"AC","name":"PEKSZX","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1813.18,1844,1625,1542.5,1501.25]}
];
for(var i=0;i<sum.length;i++){
var title = {
text: '国外航班'
};
var xAxis = {
categories:sum[0].BOOKING_Data
};
var yAxis = {
title: {
text: '绩效报告'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
};
var tooltip = {
shared: false,
useHTML: true
};
var legend = {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
};
var data0={name:sum[0].name,data:sum[0].SELL_AMPUNT};
var data1={name:sum[1].name,data:sum[1].SELL_AMPUNT};
var data2={name:sum[2].name,data:sum[2].SELL_AMPUNT};
var data3={name:sum[3].name,data:sum[3].SELL_AMPUNT};
var data4={name:sum[4].name,data:sum[4].SELL_AMPUNT};
var data5={name:sum[5].name,data:sum[5].SELL_AMPUNT};
var data6={name:sum[6].name,data:sum[6].SELL_AMPUNT};
var data7={name:sum[7].name,data:sum[7].SELL_AMPUNT};
var data8={name:sum[8].name,data:sum[8].SELL_AMPUNT};
var data9={name:sum[9].name,data:sum[9].SELL_AMPUNT};
var series=[data0,data1,data2,data3,data4,data5,data6,data7,data8,data9];
$('#select').change(function(){
series = [];
console.log(series);
$('.highcharts-line-series').hide()
//获取被选中的option标签option:selected
var ind = $(this).find('option:selected').index();
if(ind==0){
$('.highcharts-line-series').show();

            drawLineChart ()
        }else if(ind==1){
            $('.highcharts-series-0').show();
            series[0] = data0;
             //console.log(data0);               
            drawLineChart()
        }else if(ind==2){
            $('.highcharts-series-1').show();
            series[0] = data1;
            drawLineChart()
        }else if(ind==3){
            $('.highcharts-series-2').show();
            series[0] = data2;
            drawLineChart()
        }else if(ind==4){
            $('.highcharts-series-3').show();
            series[0] = data3;
            drawLineChart()
        }else if(ind==5){
            $('.highcharts-series-4').show();
            series[0] = data4;
            drawLineChart()
        }else if(ind==6){
            $('.highcharts-series-5').show();
            series[0] = data5;
            drawLineChart()
        }else if(ind==7){
            $('.highcharts-series-6').show();
            series[0] = data6;
            drawLineChart()
        }else if(ind==8){
            $('.highcharts-series-7').show();
            series[0] = data7;
            drawLineChart()
        }else if(ind==9){
            $('.highcharts-series-8').show();
            series[0] = data8;
            drawLineChart()
        }else if(ind==10){
            $('.highcharts-series-9').show();
            series[0] = data9;
            drawLineChart()
        }
    });
    drawLineChart()
    function drawLineChart () {
        var json = {};
        json.tooltip=tooltip;
        json.title = title;
        json.xAxis = xAxis;
        json.yAxis = yAxis;
        json.legend = legend;
        json.series = series;
        $('#container_1').highcharts(json);
    }
}

});

改变之后的JS
$(document).ready(function() {
var title = {
text: '国外航班'
};
var sum=[
///===============MU
{"Flight":"MU","name":"CANPEK","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1706,1290,1150,1010,1080]},
{"Flight":"MU","name":"CANSHA","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1235.78,1172.65,1092.21,1031.31,878.03]},
{"Flight":"MU","name":"PEKCAN","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1150,1195,1130,1305,1060]},
{"Flight":"MU","name":"PEKSHA","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1100.48,1072.88,1063.32,1027.02,807.2]},
{"Flight":"MU","name":"SHACAN","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1193.98,1171.92,1011.94,976.4,946.77]},
{"Flight":"MU","name":"SHAPEK","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1093.05,1091.02,1041.62,945.55,962.54]},
{"Flight":"MU","name":"SHASZX","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1255.15,1226.37,1103.55,1051.84,857.69]},
{"Flight":"MU","name":"SZXSHA","BOOKING_Data":[2,5,7,10,14],"SELL_AMPUNT":[1213.9,1240.3,1173.22,1092.39,950.37]}
];
for(var i=0;i<sum.length;i++){
var xAxis = {
categories:sum[0].BOOKING_Data
};
var yAxis = {
title: {
text: '票价金额(¥)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
};
var tooltip = {
shared: false,
useHTML: true
};
var legend = {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
};
var series=[];
for(var i=0;i<sum.length;i++){
series.push({name:sum[i].name,data:sum[i].SELL_AMPUNT});
}

     $('#select').change(function(){
         data=[];
        $('.highcharts-line-series').hide()
        console.log(data);
        //获取被选中的option标签option:selected
        var ind = $(this).find('option:selected').index();
        alert(ind);
        if(ind==0){
            $('.highcharts-line-series').show();
        
            drawLineChart ()
        }else if(ind>=1){
            $('.highcharts-series-'+(ind-1)).show();
            data[0]=series[ind-1] ;
            console.log(data)
            drawLineChart()
        }
        
    });
   
  
   
   
   $('#select').change(function(){
         data=[];
       //console.log(series);
        $('.highcharts-line-series').hide()
        //获取被选中的option标签option:selected
        var ind = $(this).find('option:selected').index();
        if(ind==0){
            $('.highcharts-line-series').show();           
            drawLineChart ()
        }else if(ind==1){
            $('.highcharts-series-0').siblings().hide();
            data[0]=series[0] ;
            console.log(series[0])
            drawLineChart()
        }else if(ind==2){
            $('.highcharts-series-1').show();
            data[0]=series[1] ;
            console.log(series[1])
            drawLineChart()
        }
   
   });
    
    drawLineChart()
    function drawLineChart () {
        var json = {};
        json.tooltip=tooltip;
        json.title = title;
        json.xAxis = xAxis;
        json.yAxis = yAxis;
        json.legend = legend;
        json.series = series;
        $('#container_3').highcharts(json);
    }

}

});
为什么没效果了呢?该怎修改呢?

爱不在就放手的主页 爱不在就放手 | 初学一级 | 园豆:7
提问于:2017-03-22 11:22
< >
分享
最佳答案
0

定义实体来接收

收获园豆:15
远扬 | 初学一级 |园豆:12 | 2017-03-22 16:49
其他回答(2)
0

这是把所有的代码都贴出来了?看了都觉得累,说说重点,你想干嘛,想改那一段代码。

龙行天涯 | 园豆:1834 (小虾三级) | 2017-03-22 14:26

可以加您的qq吗?到时候给你看看代码就知道了

支持(0) 反对(0) 爱不在就放手 | 园豆:7 (初学一级) | 2017-03-23 13:43

@爱不在就放手: 1398063934

支持(0) 反对(0) 龙行天涯 | 园豆:1834 (小虾三级) | 2017-03-23 16:23
0

存到数据库里面     后台用写代码来 返回json数据前台接收就好了,,这样太挫了

陈chenchenhehehehe | 园豆:42 (初学一级) | 2017-03-22 18:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册