将更多数据添加到Highchart的列中

问题描述 投票:0回答:1

我想在我的实际列中提供更多信息,以显示多年来风力涡轮机遇到的不同类型的事件。

我想知道是否有可能使用Highchart软件包或dplyr进行深入分析来添加此额外信息。

如果有的话,我会向您显示我正在寻找的图片:

What I want to get这是我的代码和数据框。我实际上使用mpgg_EX,但mpgg_EXimproved是获得新的结果。

[Old dataframe mpgg_EXnew dataframe not used mpgg_EXimproved

 library(dplyr)
    library(highcharter)

mpgg_EXimproved<-data.frame("Country" = c("Belux","Belux","Belux","Belux","Belux","Belux","Belux"), "WT_Manufacturer" = c("bubble","bubble","fever","fever","fever","fever","fever"), "Start_Event_Date" = c("2013", "2014","2013","2014","2015","2016","2019"),Unavailability_origin=c("MECA","MECA","OTH","MECA","MECA","MECA","OTH"),access_hub=c(1,1,0,0,1,1,0),blade=c(1,0,0,1,0,0,0),condensator=c(0,0,1,2,0,0,0),sound=c(0,0,0,0,1,0,0),fire=c(0,0,0,0,0,0,1),stringsAsFactors = FALSE)

    mpgg_EX <- data.frame("Country" = c("Belux","Belux","Belux","Belux","Belux"), "WT_Manufacturer" = c("bubble","bubble","fever","fever","fever"), "Start_Event_Date" = c("2013", "2014","2015","2016","2019"),"MECA"=c(2,1,2,1,1),"OTH"=c(1,2,0,0,0),stringsAsFactors = FALSE)
     mpgg_EX = mpgg_EX%>%
        filter(Country =="Belux") %>%
        group_by(WT_Manufacturer,Start_Event_Date)

       categories_grouped_EX <- mpgg_EX %>%
        group_by(name = WT_Manufacturer) %>%
        do(categories = as.list(.$Start_Event_Date)) %>%list_parse()
    categories_grouped_EX<- lapply(categories_grouped_EX, function(x) x[!is.na(x)])

      hc_indispo_EX <- highchart() %>%
        hc_chart(type = "column") %>%
        hc_colors(c("#fc5421","#fcf405")) %>%
        hc_title(text = "Unavailability Manufacturer Example") %>%
        hc_xAxis(title = "Suppliers"
                ,type = "category"
                ,categories = categories_grouped_EX
                 ) %>%
        hc_legend(layout = "vertical", verticalAlign = "bottom",align = "right", valueDecimals = 0, reversed = TRUE) %>%

         hc_plotOptions(
          series = list(
            cropThreshold = 1000,
            stacking = "normal",
            borderWidth = 0,
            grouping = TRUE,
            dataLabels = list(enabled = FALSE)
          )
        ) %>%
            hc_add_series(
          data = mpgg_EX,
          type = "column",
          name = "MECA",
          hcaes(x = Start_Event_Date,
                y = MECA)
         ) %>%
        hc_add_series(
          data = mpgg_EX,
          type = "column",
          name = "OTH",
          hcaes(x = Start_Event_Date,
                y = OTH)
            )  %>%
        hc_tooltip(formatter = JS("function(){
           var point = this.point;
           s = '<b>' + this.series.name + '</b>' + ' :' + Highcharts.numberFormat(this.y,0)  + '<br/>';
            s += '<b>' + 'Total : ' + '</b>' + Highcharts.numberFormat(point.stackTotal,0)  + '<br/>';
           return (s)}"
           ))
      hc_indispo_EX

我得到这个结果:enter image description here

dataframe highcharts multiple-columns
1个回答
0
投票

您已经在代码中使用了工具提示格式化程序。只需通过以下方式将其他信息添加到您的s变量中:

hc_tooltip(formatter = JS("function(){
           var point = this.point;
           s = '<b>' + this.series.name + '</b>' + ' :' + Highcharts.numberFormat(this.y,0)  + '<br/>';
           s += '<b>' + 'Something: ' + '</b>' + point.WT_Manufacturer  + '<br/>';
           s += '<b>' + 'Test: ' + '</b>' + point.Start_Event_Date  + '<br/>';
            s += '<b>' + 'Total : ' + '</b>' + Highcharts.numberFormat(point.stackTotal,0)  + '<br/>';
           return (s)}"
  ))
© www.soinside.com 2019 - 2024. All rights reserved.