項目中遇到個需求,用戶剛打開頁面時,折線圖當前日期的拐點高亮并顯示label,如圖:
可能這個需求比較特殊,度娘了半天沒有找到,最后在echarts的官方文檔中找到了,用到的是dispatchAction
這個api,
文檔如下:
觸發(fā)圖表行為,例如圖例開關`legendToggleSelect`, 數據區(qū)域縮放`dataZoom`,顯示
提示框`showTip`等等
文檔傳送門
demo如下:
//這里我們模擬鼠標的點擊事件
myChart.dispatchAction({
type: 'highlight',
dataIndex:that.date-1
});
action.highlight
高亮指定的數據圖形。
通過seriesName
或者seriesIndex
指定系列。如果要再指定某個數據可以再指定dataIndex
或者name
。
dispatchAction({
type: 'highlight',
// 可選,系列 index,可以是一個數組指定多個系列
seriesIndex?: number|Array,
// 可選,系列名稱,可以是一個數組指定多個系列
seriesName?: string|Array,
// 可選,數據的 index
dataIndex?: number,
// 可選,數據的 名稱
name?: string
})