代码之家  ›  专栏  ›  技术社区  ›  patL grad student

内半径极高宪章

  •  0
  • patL grad student  · 技术社区  · 6 年前

    highcharter 所以我可以通过这样的工具提示来可视化数据 D3 fivethirtyeight .

    solid gauge 就像在 this 例如,但是我希望数据在 polar .

    我试着改变 innerSize innerRadius 参数,但我不能完成它。

    这是我的 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


    编辑

    在@ppotachek的回答之后,我更新了他的图表,所以所需的更新如下:

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  1
  •   ppotaczek    6 年前

    要在海图极坐标图中获得类似的结果,应设置 点填充 组填充 到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/