简体   繁体   English

在 Rails 上使用 Chartkick/Highcharts 的混合图表类型

[英]Mixed Chart Types using Chartkick/Highcharts on Rails

I'm trying to create a mixed column/line chart using Highcharts.我正在尝试使用 Highcharts 创建混合柱形图/折线图。

I've been trying to use the library functionality to set one of my data series to be of type "line".我一直在尝试使用library功能将我的数据系列之一设置为“行”类型。 I have tried a few different approaches, but I can't seem to figure out how to pass the type parameter of a given series using the Highcharts API.我尝试了几种不同的方法,但似乎无法弄清楚如何使用 Highcharts API 传递给定系列的类型参数。

<%= column_chart( ChartData.new(@forecast).revenue_and_net_income, library: {
  title: {
    text: "Revenue and Net Income"
  },
  series: [{
    1 => {
      type: "line"
    }
  }],
} ) %> 

Where my data come from the following method:我的数据来自以下方法:

def revenue_and_net_income
data = [
  {
    name: "Revenue",
    data: revenue_by_year
  },
  {
    name: "Net Income",
    data: net_income_by_year,
  }
]

end结束

Not sure what I'm doing wrong?不确定我做错了什么? I only seem to be able to access the Highcharts API methods listed under 'Chart', none of the series options etc. seem to work.我似乎只能访问“图表”下列出的 Highcharts API 方法,所有系列选项等似乎都不起作用。 Can anyone point me in the right direction for how to successfully get this to work?任何人都可以指出我如何成功使其发挥作用的正确方向吗?

you can try this way.你可以试试这个方法。

<%= line_chart [
        {
            name: "Amount", type: "column", data: @cause.donations.map {
                |t| [t.user.name, t.amount] 
            }
        },
        {
            name: "Test", type: "line", data: @cause.donations.map {
                |t| [t.user.name, t.amount]
            }
        }
    ],
    prefix: "$",
    adapter: "highcharts"
%>

just don't care line_chart , column_chart or anythings... ONLY custom type in data.只是不关心line_chartcolumn_chart或任何东西......只有自定义type的数据。 OK好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM