【问题标题】:Change Fontsize and boxsize in highchart R在highchart R中更改字体大小和boxsize
【发布时间】:2021-10-09 10:01:36
【问题描述】:

我正在尝试创建一个自动化的组织结构图。 但它是不可读的。我想更改字体大小和框的大小

代码如下

pl <- highchart() %>%
  hc_chart(type = 'organization') %>%
  hc_title(text = 'Klarna ownership structure')%>%
  hc_caption(text = 'Ownership from left to right')%>%
  hc_add_series(
    data = list(
      list(from = 'Klarna Holding AB Sweden', to = 'Klarna Runway AB Sweden', weight = 1),
      list(from = 'Klarna Runway AB Sweden', to = 'Toplooks LCC USA', weight = 1),
      list(from = 'Klarna Holding AB Sweden', to = 'Larkan Holding AB Sweden', weight = 1),
      list(from = 'Larkan Holding AB Sweden', to = 'Larkan AB', weight = 1),
      list(from = 'Larkan Holding AB Sweden', to = 'Klarna Midco AB Sweden', weight = 1),
      list(from = 'Klarna Holding AB Sweden', to = 'Klarna Midco AB Sweden', weight = 1),
      list(from = 'Larkan AB', to = 'Klarna Bank AB Sweden', weight = 1),
      list(from = 'Klarna Midco AB Sweden', to = 'Klarna Bank AB Sweden', weight = 1),
      list(from = 'SEQUOIA CAPITAL United Kingdom', to = 'Klarna Holding AB Sweden', weight = 1),
      list(from = 'Silver Lake Partners USA', to = 'Klarna Holding AB Sweden', weight = 1),
      list(from = 'Bestseller Group Denmark', to = 'Klarna Holding AB Sweden', weight = 1),
      list(from = 'Dragoneer USA', to = 'Klarna Holding AB Sweden', weight = 1),
      list(from = 'Permira UK', to = 'Klarna Holding AB Sweden', weight = 1),
      list(from = 'Visa USA', to = 'Klarna Holding AB Sweden', weight = 1),
      list(from = 'Atomico UK', to = 'Klarna Holding AB Sweden', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Analyzd Technologies Ltd Cyprus', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Ident Inkasso AB Sweden', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Australia Holding Pty Ltd Australia', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Austria GmbH Austria', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Belgium N.V Belgium', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna B.V. The Netherlands', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Germany Holding GmbH Germany', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna GmbH Germany', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Inc The United States', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Italy S.r.l. Italy', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Norge AS Norway', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Oy Finland', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna Spain S.L. Spain', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Klarna UK Limited UK', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'Search Engine Marketing Sweden AB Sweden', weight = 1),
      list(from = 'Klarna Bank AB Sweden', to = 'BillPay GmbH  Germany', weight = 1),
      list(from = 'Klarna Germany Holding GmbH Germany', to = 'Sofort GmbH', weight = 1),
      list(from = 'Klarna Australia Holding Pty Ltd Australia', to = 'Klarna Australia Pty Ltd Australia', weight = 1),
      list(from = 'Klarna Australia Holding Pty Ltd Australia', to = 'Klarna New Zealand Ltd New Zealand', weight = 1),
      list(from = 'Analyzd Technologies Ltd Cyprus', to = 'Klarna Ltd ?', weight = 1)
      ))%>%
  hc_theme(hc_theme_ft())

pl

如何更改字体大小和框的大小? 试图用谷歌搜索它,但它始终是 java 或其他东西,我无法将它正确转换为 R。

问候克里斯蒂安

【问题讨论】:

    标签: r highcharts font-size


    【解决方案1】:

    您可以在 R 中封装 JavaScript 代码,以使用 Highcharts JS API 来实现此目的。你可以在这里找到一篇解释如何做到这一点的文章:https://www.highcharts.com/blog/tutorials/working-with-highcharts-javascript-syntax-in-r/?fbclid=IwAR1AipximplJVYVQbBerc2nu7xDe3Vn7o4HOtmPMU_Ntrzf4SgLyNtc9KVk

    然后使用 dataLabels.style.fontSize 选项更改文本大小: https://api.highcharts.com/highcharts/series.organization.dataLabels.style.fontSize

    关于更改节点的高度,这里是一个附加选项,例如高度。就像我在下面的演示中所做的那样:

    library(highcharter)
    
    highchart() %>%
      hc_chart(type = 'organization') %>%
      hc_add_series(
        data = list(
          list(from = 'Brazil', to = 'Portugal'),
          list(from = 'Brazil', to = 'Spain'),
          list(from = 'Poland', to = 'England'))
      ) %>%
    
    hc_chart(events = list(load = JS("function() {
          var chart = this;
          chart.update({
            chart: {
              backgroundColor: '#FCFFC5'
            },
            plotOptions: {
                  series: {
                      dataLabels: {
                          style: {
                            fontSize: '6px'
                        }
                    },
                    nodes: [{
                      id: 'Brazil',
                      height: 20
                    }]
                  }
                }
            })
          }
        ")
    ))
    

    【讨论】:

    • 啊,谢谢!现在需要转移到另一个任务。但我会尽快检查出来!
    猜你喜欢
    • 2019-01-02
    • 2011-06-25
    • 2022-08-24
    • 2017-10-21
    • 2020-09-14
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    相关资源
    最近更新 更多