i would like to ask is that possible using Chart.js http://www.chartjs.org/ to get Combined Bar and line charts?
Thanks for any advice.
i would like to ask is that possible using Chart.js http://www.chartjs.org/ to get Combined Bar and line charts?
Thanks for any advice.
One minor code addition is needed. In the "buildScale" section, you need to include the data from eachPoints as well. This is, because calculatedY is only using the data from bar to determine the height; the data using line is ignored. If the data using the line is higher than the data using bar, the line graph will be cut off at the top.
This worked for me to change the z-index of lines and bars. Swap the next two code blocks:
Like this:
Good luck.
The below answer is concerned with chart.js 1.x. Chart.js 2.x supports this Chart.js how to get Combined Bar and line charts?
EDIT 2 I have now added this feature to my custom build of chartjs if you want to use that https://github.com/leighquince/Chart.js the only difference is i named it Overlay not LineBar so to use it just create a graph using
var myOverlayChart = new Chart(lineBar).Overlay(data);
everything else is the same though.Ok so had a quick go at seeing if this was possible and the short answer is yes but would need more work truly integrate this into the build of chart js. Here is a fiddle showing it in action with a line and bar chart to compare against: http://fiddle.jshell.net/leighking2/898kzyp7/
So my solution was to create a new chart type called LineBar (could have gone for the extending option but before starting I felt like this was going to need a lot of method overriding so went for a new graph, it also means i didn't have to re-declare helpers as Chart.helpers not a huge thing but was reason enough at the time).
At it's core it is the bar chart but it keeps a track of datasets in separate
lineDataSets
andbarDataSets
variables. Then when it needs to draw/check-events /use-the-data it loops other both of the new datasets separately.Whenever it is looping over the
lineDataSets
variable it is performing code from the current line graph and visa versa for the bar graphSo i'll paste the new graph at the bottom of this answer as it's pretty large, to use it copy and paste it into your own chart.js file at the bottom or paste it after you include chart.js on your page.
To then make use of it you can now declare your data with an extra option called
type
then just create a new chart of type LineBar
result
EDIT: Updated it so now it has the tooltips and removeData/addData functionality working. See the fiddle for examples of these. You can also add as many datasets as you like both line and bar and it will display them all on the same graph.
Limitation - if bar and line get updated their respective pieces have to be updated here as well which isn't great, they won't break if bar and line get updated it just might mean they don't look the same whatever gets updated
and here is the actual new chart
but we want to show gridlines
With Chart.js 2.0 you do it like this:
New version of Charts.js (v2.0) supports combined Bar and Line Chart.
v2.0 is currently in Beta
Link to Plunker