我希望创建一个基于this JSfiddle的覆盖零碎的高 map .我使用了events = list(load = JS()
构造来调用JS代码,复制自上面的演示.我遇到的问题,如下所示,是输出只包含一个piechart,而它应该包含一个piechart用于序列中每个非缺失点.
此外,我注意到饼图呈现在 map 的中心,但工具提示和数据是数据系列的最后一点—这里是SE(我认为瑞典!).同样重要的是,饼图总是呈现在同一个位置,而不管data
个国家的id
个.我做错什么了?我附上下面的输出图像,以及复制映射的代码.
Update 多亏了费利克斯·贾斯勒的 comments ,我意识到每个饼图实际上都在绘制,但问题是,他们都在同一个地方绘制.在饼图上启用标签可以清楚地看到这一点,如下面更新的图像输出所示.此外,我还发现了this post个,vue.JS中的highcharts用户遇到了完全相同的问题.这里的解决方案是用户更新到最新版本的highcharts v10.2.我有最新版本的highcharter(v9.4),所以我认为这个解决方案可能需要highcharter开发人员的一些投入.我开了一个关于高宪章git的问题here.
Final update The answer given below by jedrzerjuta has been accepted with much gratitude and the result can be seen below.
# Required
library(tidyverse)
library(highcharter)
# Create data
data <- tibble(
id = c(
"PL",
"NO",
"DE",
"BY",
"FR",
"CZ",
"SE"
),
successes = c(
15,
20,
10,
10,
1,
20,
20
),
failures = c(
3,
2,
10,
15,
2,
20,
8
)
)
data$value <- data$successes-data$failures
# Plot
hcmap("custom/world-highres",
data = data,
joinBy = c("iso-a2", "id"),
keys =c('id', 'successes', 'failures', 'value')
)%>%
hc_colorAxis(
dataClasses=list(
list(
from = -15,
to = -1,
color = '#faa',
name = 'Successes'
),
list(
from = 0,
to = 0,
color = '#ddd',
name = 'Neutral'
),
list(
from = 1,
to = 18,
color = '#adf',
name = 'Neutral'
)
)
)%>%
hc_chart(events = list(load = JS("function() {
var chart = this;
chart.series[0].points.forEach(country => {
if (!country.isNull) {
chart.addSeries({
type: 'pie',
name: country.id,
zIndex: 4,
size: 40,
dataLabels: {
enabled: false
},
onPoint: {
id: country.id
},
states: {
inactive: {
enabled: true
}
},
data: [{
name: 'Successes',
y: country.successes,
color: '#adf'
}, {
name: 'Failures',
y: country.failures,
color: '#faa'
}]
}, false);
}
}
);
chart.redraw();
}
"
)
)
)