highcharts - 动态更改条形颜色 - highcharts
问题描述
我是一名R
程序员,试图JS
通过包解析一些代码highcharter
。
我正在尝试根据此问题使用此示例更改悬停时的每个条形颜色。
我试过这个:
plotOptions: {
column: {
events: {
mouseOver: function () {
this.chart.series[this.index].update({
color: 'blue'
});
},
mouseOut: function () {
this.chart.series[this.index].update({
color: '#b0b0b0'
});
}
};
states: {
hover: {
color: colors[x]
}
}
}
}
但是我只能用“蓝色”突出显示。如何使用不同的颜色来表示不同的颜色column
?
谢谢你。
解决方案
您只能在所有列上看到蓝色,因为您将这些事件设置为系列。为了实现它,您可以创建带有颜色的数组并将其分配给 上的一般图表对象chart.events.load
。然后在series.point.events.mouseOver
并且mouseOut
应该可以通过点索引来改变颜色。这是示例代码:
highchart() %>%
hc_chart(events = list(
load = JS("function() {this.customColors = ['red', 'green', 'blue']}")
)) %>%
hc_series(
list(
data = abs(rnorm(3)) + 1,
type = "column",
color = '#ddd',
point = list(
events = list(
mouseOver = JS("function() {this.update({color: this.series.chart.customColors[this.index]})}"),
mouseOut = JS("function() {this.update({color: '#ddd'})}")
)
)
)
)
API参考:
https://api.highcharts.com/highcharts/series.column.point.events
推荐阅读
- javascript - Next Js & Typescript - 类型上不存在属性 setState 示例
- sql - 如果我们只知道user_id、actions_made和访问时间,使用SQL查询user_id、会话开始和结束时间
- javascript - 使用 AJAX 在同一页面上将 Javascript var 传递给 PHP
- authentication - 如何在 ASP.NET Core 2.1 中对两种类型的身份验证进行身份验证?
- android - findViewById 无法构建 WebView
- bash - 使用 lsof 跟踪通过命令行运行的脚本打开的文件
- mysql - 为什么我们需要约束关键字来添加外键,而在删除外键时不需要?
- javascript - 如何在 Chrome 扩展中拦截本地存储时防止堆栈溢出
- javascript - 使用正则表达式通过 PHP 缩小 JS
- java - 使用函数将元素添加到类数组。处理 3 中的“绘画”