1. 程式人生 > 其它 >echarts預設選中且顯示文字

echarts預設選中且顯示文字

 // 使用剛指定的配置項和資料顯示圖表。
        myChart2.setOption(option);
        //設定預設選中高亮部分
        let index = 0;
        myChart2.dispatchAction({
            type: 'highlight',
            seriesIndex: 0,
            dataIndex: 0
        });
        // 當滑鼠移入時,如果不是第一項,則把當前項置為選中,如果是第一項,則設定第一項為當前項
        myChart2.on('mouseover', function
(e) { myChart2.dispatchAction({ type: 'downplay', seriesIndex: 0, dataIndex: 0 }); if (e.dataIndex != index) { myChart2.dispatchAction({ type: 'downplay', seriesIndex:
0, dataIndex: index }); } if (e.dataIndex == 0) { myChart2.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: e.dataIndex }); } });
//當滑鼠離開時,把當前項置為選中 myChart2.on('mouseout', function(e) { index = e.dataIndex; myChart2.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: e.dataIndex }); }); myChart2.dispatchAction({ type: 'showTip', seriesIndex: 0, // 顯示第幾個series dataIndex: 0 // 顯示第幾個資料 });