首页 文章

rCharts - Highcharts气泡图的数据标签

提问于
浏览
0

我正在使用rCharts创建Highcharts气泡图,但无法更改气泡标签 . 在此示例中,我希望分支名称显示在气泡中而不是默认y . 示例数据和我正在使用的代码:

branch <- c('A', 'B', 'C', 'D', 'E', 'F')
cases <- c('100', '200', '300', '400', '500', '600')
prop <- c('600', '500', '400', '300', '200', '100')
units <- c('6', '5', '4', '3', '2', '1')
size <- c('large', 'large', 'large', 'medium', 'small', 'small')
df <- data.frame(branch, cases, prop, units, size)

library(rCharts)

h1 <- hPlot(x = "prop", y = "units", data = df, type = "bubble", group = "size", size = "cases", name = "branch")

h1$plotOptions(bubble =list(dataLabels = list(enabled = TRUE, x = 0,
                                          formatter = "#! function() {
                                          return this.point.name;} !#"
                                          )))

所有帮助表示赞赏!谢谢!

1 回答

  • 0

    在hPlot中,您无法在toolTip或plotOptions中使用未使用的colomn .

    尝试使用以下代码,而不是使用名称Y:

    branch <- c('A', 'B', 'C', 'D', 'E', 'F')
    cases <- c(100, 200, 300, 400, 500, 600)
    prop <- c(600, 500, 400, 300, 200, 100)
    units <- c(6, 5,4, 3, 2, 1)
    size <- c('large', 'large', 'large', 'medium', 'small', 'small')
    df <- data.frame(branch, cases, prop, units, size)
    
    library(rCharts)
    
    h1 <- hPlot(x = "prop", y = "units", type = "bubble", group = "size", size = "cases", name = "branch", data = df)
    
    h1$plotOptions(series=list(dataLabels=list(enabled=TRUE, format = '{y}')))
    
    h1
    

    如您所见,这将显示气泡中的y值 . 您也可以显示x值 . 但就是这样 . 这是由于气泡图的结构 . 但是有一个解决方法 . 有关详细信息,请参阅https://github.com/ramnathv/rCharts/issues/289 .

相关问题