简体   繁体   中英

Mixed Chart Types using Chartkick/Highcharts on Rails

I'm trying to create a mixed column/line chart using Highcharts.

I've been trying to use the library functionality to set one of my data series to be of type "line". 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.

<%= 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. 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. OK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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