内半径极高

时间:2018-08-13 12:40:25

标签: r highcharts r-highcharter

我正在尝试使用highcharter来更改极坐标图的内半径,因此我可以像从fivethirtyeight来的D3图表一样,通过工具提示来可视化数据。 / p>

我知道可以像this一样使用solid gauge可视化数据,但是我希望数据在polar中可见。

我尝试更改innerSizeinnerRadius参数,但无法完成。

这是我的R代码:

library(tidyverse)
library(highcharter)
highchart() %>% 
  hc_chart(polar = T, type = "bar") %>% 
  hc_title(text = "Athlete 1 vs Athlete 2") %>% 
  hc_xAxis(categories = c("Total Score", "Avg. Score", "Sum Score",
                          "Best Score"),
           tickmarkPlacement = "on",
           plotLines = list(
             list(label = list(
               rotation = 90))
             )
           ) %>% 
  hc_yAxis(min = 0) %>% 
  hc_series(
    list(
      name = "Athlete 1",
      data = c(43000, 19000, 60000, 35000)
    ),
    list(
      name = "Athlete 2",
      data = c(50000, 39000, 42000, 31000)
    )
  ) %>% 
  hc_colors(c("firebrick", "steelblue"))

所需的输出如下所示: enter image description here

谢谢!


编辑

在@ppotaczek回答后,我已经更新了他的图表,因此所需的更新将如下所示:

enter image description here

1 个答案:

答案 0 :(得分:1)

要在Highcharts极坐标图中获得相似的结果,应将 pointPadding groupPadding 设置为0。要在图形中间创建空白,可以使用Highcharts .SVGRenderer和yAxis的偏移量

Highcharts.chart('container', {
    chart: {
        polar: true,
        type: 'bar',
        events: {
            render: function() {
                var chart = this,
                    middleElement = chart.middleElement;

                if (middleElement) {
                    middleElement.destroy();
                }

                chart.middleElement = chart.renderer.circle(chart.plotSizeX / 2 + chart.plotLeft, chart.plotHeight / 2 + chart.plotTop, 20).attr({
                    zIndex: 3,
                    fill: '#ffffff'
                }).add();
            }
        }
    },
    yAxis: {
        offset: 20
    },

    series: [{
        pointPadding: 0,
        groupPadding: 0,
        name: "Athlete 1",
        data: [43000, 19000, 60000, 35000]
    }, {
        pointPadding: 0,
        groupPadding: 0,
        name: "Athlete 2",
        data: [50000, 39000, 42000, 31000]
    }]
});

实时演示:http://jsfiddle.net/BlackLabel/y6uL180j/

API参考:https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#circle

编辑: 要在图表中间显示悬停点的值,请使用带有适当选项的工具提示:

tooltip: {
    borderWidth: 0,
    backgroundColor: 'none',
    shadow: false,
    style: {
        fontSize: '16px'
    },
    headerFormat: '',
    pointFormatter: function() {
        return this.y / 1000 + 'k'
    },
    positioner: function(labelWidth, labelHeight) {
        return {
            x: (this.chart.plotSizeX - labelWidth) / 2 + this.chart.plotLeft,
            y: (this.chart.plotSizeY - labelHeight) / 2 + this.chart.plotTop
        };
    }
}

实时演示:http://jsfiddle.net/BlackLabel/5ybhtrmz/