【问题标题】:Chartkick Pie chart legend customisationChartkick 饼图图例自定义
【发布时间】:2016-12-09 09:52:06
【问题描述】:

我在 chartkick 中使用 highcharts 库来绘制图表。

我需要自定义饼图的图例,但我可以做到。

我的代码是

<%= pie_chart Question.group(:user_id).count %>

这会导致

但我需要类似的东西

ie) 我需要单独显示图例。

不要考虑图例中的数据,它只是一个样本数据,可能在两个图表中有所不同。

【问题讨论】:

    标签: ruby-on-rails charts highcharts chartkick


    【解决方案1】:

    您需要编辑饼图的默认选项。

    1. 禁用数据标签:http://jsfiddle.net/qor8fhqb/2/

      plotOptions: {
        pie: {
          dataLabels: {
            enabled: false
          }
        }
      },
      
    2. 启用在图例中显示饼系列http://jsfiddle.net/qor8fhqb/3/

      series: [{
        showInLegend: true,
      
    3. 自定义图例符号http://jsfiddle.net/qor8fhqb/4/

      legend: {
       symbolWidth: 40,
       // symbolHeight: 20,
       squareSymbol: false,
       symbolRadius: 0
      },
      

    这是一个没有任何包装器的纯 Highcharts 配置。

    【讨论】:

    • 你知道如何通过点击这个饼图的饼图获得饼图标题吗?
    猜你喜欢
    • 2014-10-08
    • 1970-01-01
    • 2021-01-05
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 1970-01-01
    相关资源
    最近更新 更多