Created
July 22, 2019 10:00
-
-
Save hungtcs/3ba0f26676123fff313ad12d6eb2e303 to your computer and use it in GitHub Desktop.
echarts tooltip formatter function with unit supported
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { EChartOption } from 'echarts'; | |
declare interface _Format extends EChartOption.Tooltip.Format { | |
marker: string; | |
axisValueLabel: string; | |
} | |
const formatter: EChartOption.Tooltip.Formatter = function(params: _Format|Array<_Format>, _ticket, _callback) { | |
if(params instanceof Array) { | |
if(params.length) { | |
let message = ''; | |
message += `${ params[0].axisValueLabel }`; | |
params.forEach(param => { | |
message += `<br/>${ param.marker }${ param.seriesName }: ${ param.value }${ param.data.unit || '' }`; | |
}); | |
return message; | |
} else { | |
return null; | |
} | |
} else { | |
let message = ''; | |
message += `${ params[0].axisValueLabel }`; | |
message += `<br/>${ params.marker }${ params.seriesName }: ${ params.value }${ params.data.unit || '' }`; | |
return message; | |
} | |
}; | |
export default formatter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage