【问题标题】:set font size of sankey chart in HIghcharter for R在 R 的 HIghcharter 中设置 sankey 图表的字体大小
【发布时间】:2020-01-19 13:18:27
【问题描述】:

我在 Hichcharts 中使用 R 完成了一个很酷的 sankey 图表。 结束节点的字体非常小,我喜欢,所以我想知道如何使它更大(容器也必须更宽)。

highchart() %>%
  hc_chart(type = 'sankey') %>%
  hc_add_series(
      data = list(
        list(from = 'FOOD', to = "M", weight = 10),
        list(from = 'CARS', to = "M",  weight = 50),
        list(from = 'READING', to = "M",  weight = 45),list(from = 'FOOD', to = "F", weight = 100),
        list(from = 'CARS', to = "F",  weight = 56),
        list(from = 'READING', to = "F",  weight = 25))
      )

【问题讨论】:

    标签: r highcharts r-highcharter


    【解决方案1】:

    您可以使用 series.nodeWidth 属性增加节点宽度,但它仅适用于所有节点。如果您只想为特定节点设置它,则必须更改 Highcharts 核心代码。

    您可以在 dataLabels.nodeFormatter 中更改的字体大小。这是一个纯 JavaScript 示例:https://jsfiddle.net/BlackLabel/9tL2zogq

    nodeWidth: 50,
        dataLabels: {
          nodeFormatter() {
            if (this.key === 'M' || this.key === 'F') {
              return '<span style="font-size: 22px;">' + this.key + '</span>'
            } else {
              return this.key
            }
          }
        },
    

    如果您在将其重写为 R 时遇到任何问题,请告诉我,届时我将编辑我的答案。 您可以使用 JS() 方法将 JS 函数注入到 R 中。

    【讨论】:

      猜你喜欢
      • 2020-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多