1. 程式人生 > >echarts例項 動態更新 資料問題,點選事件觸發多次

echarts例項 動態更新 資料問題,點選事件觸發多次

 function reloadTable() {
      var iii = layer.load(1, {shade: [0.1,'#fff'] });//提交的動畫
   url = "change/query?selectType=" + $("#selectType").val() + "&xlName=" + $("#xlname").val()+"&stationid="+$("#station").val();
    $.get(url, function (data) {
         layer.close(iii)//銷燬動畫
var memoLegend = []
var memoList = []
echarts.init(document.getElementById('memoBar')).dispose();//銷燬前一個例項
memoBar = echarts.init(document.getElementById('memoBar'));//構建下一個例項
    option = 
     title : {
                text: '變更原因次數',
            },
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 座標軸指示器,座標軸觸發有效
            type : 'shadow'        // 預設為直線,可選為:'line' | 'shadow'
        }
    },
    legend: {
        data:['次數']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [{
            type : 'value'
        }],
    yAxis : [{
            type : 'category',
            axisTick : {show: false},
            data : memoLegend
        }],
    series : [{
            name:'次數',
            type:'bar',
            label: {
                normal: {
                    show: true
                }
            },
            data:memoList
        }]
    };
 memoBar.setOption(option, true);


});
}
 memoBar.on('click', function (param) {
    console.log('點選了我!');
     console.log(param)
});
當然 先銷燬再建立就不