highcharts - Highcharts - 自定义树状图的图例
问题描述
我目前正在使用 highcharts 创建一个树形图来显示我的数据。我正在尝试自定义图表的图例,以便仅在图例中显示parents
名称和颜色。
例如,这些是我的数据对象中的父 ID 名称
{
id: 'low',
color: "#0D6302"
}, {
id: 'med-low',
color: "#0B7070"
}, {
id: 'med',
color: '#DC9603'
}, {
id: 'med-high',
color: '#DD5F0C'
}, {
id: 'high',
color: "#C50710"
}
我只想在我的图例中显示:green "low", blue "med-low", yellow "med", orange "med-high and red "high"
这是我目前传奇的照片
我不想展示“零售、在线、实体店、电子商务、服装、约会和街头小贩”。
我已经通过在我的系列中使用showInLegend: true
和尝试了这一点。legendType: "point"
这是一个 jsfiddle 示例的链接:https ://jsfiddle.net/bahsm5t1/13/
解决方案
您可以使用下面的自定义代码隐藏这些图例点,这些代码可以使用加载回调访问它们。
chart: {
events: {
load(){
let chart = this;
chart.legend.allItems.forEach(item => {
if(item.parent) {
item.legendGroup.hide();
}
})
}
}
},
演示:https ://jsfiddle.net/BlackLabel/uknf8xws/
API:https ://api.highcharts.com/highcharts/chart.events.load
推荐阅读
- c# - 带句点的 ASP Net Core 十进制输入变成整数
- git - Git:如何在不暂存文件进行删除的情况下取消跟踪文件
- javascript - javascript深度克隆无法正常工作
- oracle - 在 WebLogic 12c 服务器上启动管理服务器时出错
- excel - 转置一列并保持相对值
- elasticsearch - 从观察者 api 中的 ctx.payload 循环返回的文档数量增加 - Elasticsearch
- python - 使用 for 循环保存具有不同名称的多个图像
- mysql - SQL 语法“ALTER TABLE 表名”有什么问题?
- node.js - 如何使用 Mongoose 和 MongoDB 自动交叉填充集合?
- python-3.x - 如何用另一个数据框替换一个数据框?