javascript - 在 HIGHCHARTS 中动态设置工具提示
问题描述
我在我的应用程序中使用 Highcharts。在这里,我面临一个问题,例如,
我的 x 轴列表是,
var peMList = ["EM", "UF", "WT"];
我的对象喜欢,
var mapObj = {};
mapObj["EM"]="Element_Missing";
mapObj["UF"]="Unknown_Format";
mapObj["WT"]="Wrong_Type";
我的图表格式像,
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>'+mapObj['{point.key}'],
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}% </b><br/>',
shared: true
}
如何在图表工具提示中添加对象值。我已经添加了但是,它显示未定义。
任何帮助将不胜感激。
解决方案
你必须使用formatter
功能:
tooltip: {
formatter: function() {
return '<span style="font-size:10px">' + this.points[0].key + '</span><table>' + mapObj[this.points[0].key] + '</table><br/>' + '<span style="color:' + this.points[0].series.color + '">' + this.points[0].series.name + '</span>: <b>' + this.points[0].y + '% </b>'
},
shared: true
}
现场演示:http: //jsfiddle.net/BlackLabel/jvg0fk7y/
API 参考:https ://api.highcharts.com/highcharts/tooltip.formatter
推荐阅读
- python - 使用 DatetimeIndex 重新采样 DataFrame 并保持日期范围
- amazon-web-services - 是否可以在 EC2 上运行 docker?
- ruby-on-rails - 如何在 Rails 中同时使用 form_with 和 simple_form_for?
- javascript - 刷新 currentsong 广播
- python - Python 是否支持等距照片?
- outlook - Outlook 邮件正文仅返回最近的邮件
- docker - 当我在 Ubuntu 16.04 上下载大文件 (40GB) 时,Docker 构建崩溃
- facebook-graph-api - 通过 API 按名称搜索 Instagram 用户
- reactjs - 来自 React Material-UI 怪异 API 的排版组件
- jquery - ParamQuery 获取父行