ankane / chartkick

Create beautiful JavaScript charts with one line of Ruby
https://chartkick.com
MIT License
6.33k stars 565 forks source link

Add combo bar/line charts #602

Closed jmarbach closed 1 year ago

jmarbach commented 1 year ago

As a developer I want to be able to combine multiple chart types, such as line and bar charts So that I can create visualizations that show a series and an aggregation of a series in one graph

Given a developer wants to show bar and line charts at once When the developer configures their chartkick chart Then they specify combo_bar_line and within the data array they specify the two series to display

e.g.

<%= combo_bar_line [
    {
      name: "Series 1",
      data ...,
      dataset: { }
    },
    {
      name: "Series 2",
      data: ...,
      dataset: { }
    }
  ]
%>

Context

ankane commented 1 year ago

Hey @jmarbach, thanks for the suggestion, but I'm not looking to add any more chart types right now.

suxur commented 1 year ago

@jmarbach This can be achieved already, though it's not very apparent. You just need to pass the type of chart you want in one of the datasets. Taking your example, you can do...

<%= line_chart [
    {
      name: "Series 1",
      data ...,
      dataset: {
        type: "line"
       }
    },
    {
      name: "Series 2",
      data: ...,
      dataset: { 
        type: "bar"
      }
    }
  ]
%>
armanivvv commented 3 months ago

@jmarbach This can be achieved already, though it's not very apparent. You just need to pass the type of chart you want in one of the datasets. Taking your example, you can do...

<%= line_chart [
    {
      name: "Series 1",
      data ...,
      dataset: {
        type: "line"
       }
    },
    {
      name: "Series 2",
      data: ...,
      dataset: { 
        type: "bar"
      }
    }
  ]
%>

Amazing. I was already looking for another charting package. This saved me 95% of the way. Now to figure out if it can be forced in the HighCharts adapter.

SCR-20240614-mymp