How to make 3 levels drilldown plot in R highcharter (possible other packages)

后端 未结 2 607
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 14:46

today i started my adventure with highcharter package. I\'m interested in drilldown plots.

(fast check what i want to create without r)

http://jsfiddle.net/g

2条回答
  •  隐瞒了意图╮
    2020-12-15 15:26

    If you want a multilevel drilldown you have to set id of the drilldown to the data point just like in the pure js highcharts.

    Example: http://jsfiddle.net/6LXVQ/2/ and the most important part:

    drilldown: {
            series: [{
                id: 'animals',
                name: 'Animals',
                data: [{
                    name: 'Cats',
                    y: 4,
                    drilldown: 'cats'
                }, ['Dogs', 2],
                    ['Cows', 1],
                    ['Sheep', 2],
                    ['Pigs', 1]
                ]
            }, {
    
                id: 'cats',
                data: [1, 2, 3]
            }]
        }
    

    You can see here that your data points are not only numbers but objects which containts link to the drilldown series.

    An example using Highcharter - simplified but you should get the idea:

    hc <- highchart() %>%
        hc_chart(type="column") %>%
        hc_xAxis(type="category") %>%
        hc_add_series(
            name = "Things",
            data = list(
                list(
                    name = "Animals",
                    y = 10,
                    drilldown = "animals"
                )
            )
        ) %>%
    
        hc_drilldown(
            series = list(
                list(
                    name = "Animals",
                    id = "animals",
                    data = list(
                        list(
                            name = "Cats",
                            y = 2,
                            drilldown = "cats"
                        )
                    )
                 ),
                 list(
                     name = "Cats",
                     id = "cats",
                     data = list(list(name = "white cats", y = 2), list(name = "black cats", y = 3), list(name = "red cats",y = 4))
                 )
             )
         )
    hc
    

提交回复
热议问题