In This article, we will discuss how we can Mixed Bar and Line chart with different scales using Chart.js. First, let you know that it is possible to create a Bar and Line chart mixed chart in Chart js.
A combination chart is very useful for representing the data to the use, combination chart is a visualization that combines the features of multiple graph types in one graph for example we can combine a bar chart and the line chart. using that combination chart show the data using several bars and or lines, each of which represents a particular dataset.
A mix of bars and lines in the same graph can be useful when comparing values in different datasets since the mix provides a clear view of which dataset is high, lower, or equal.
Combo Bar Line Chart with Chart.js Example
Let’s understand with an example using the chart js, let’s I want to create a combination chart to compare the projected sales with the real sales for each month.
Our example below contains two series, in which the bars describe the projected sales for each month in a calendar year, and the line chart describes the real sales for the same months done by our company.
<!DOCTYPE html>
<html>
<head>
<title>Createbar chart with Line Chart Using chart.js</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.7.1/dist/chart.min.js"></script>
</head>
<body>
<div style="margin-left:5%;margin-right:5%">
<canvas id="barchartwithlinechartcanvas" style="width:80%"></canvas>
</div>
<script>
var BarchartwithlineDataobj = {
labels: [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"June",
"July",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
],
datasets: [
{
label: "Projected sales",
backgroundColor: "red",
borderColor: "red",
borderWidth: 1,
data: [42, 56, 9, 52, 66, 87, 51, 42, 32, 88,150,125],
order: 1
},
{
label: "Actual Sales",
backgroundColor: "blue",
borderColor: "blue",
borderWidth: 1,
data: [0, 52, 94, 62, 12, 45, 110, 52, 39, 75,115,175],
type: 'line',//sepcify this dataset is for line chart
order: 0 //to set the linechart on top of barchart
}
]
};
var LinebarChartOptions = {
responsive: true,
plugins: {
legend: {
position: 'right',//this option is used for place legend on the right side of bar chart
}
},
title: {
display: true,
text: "Chart.js Bar Chart with Line Chart"
}
}
window.onload = function () {
var chartData = {
type: "bar",
data: BarchartwithlineDataobj,
options: LinebarChartOptions
}
new Chart("barchartwithlinechartcanvas", chartData);
};
</script>
</body>
</html>
Codepen Editor
The post [Simple Trick]-How to Combined Bar and line charts Using Chart.js? appeared first on Software Development | Programming Tutorials.
Read More Articles
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- jQuery Ajax GET Example with Parameters
- How to Pass Parameters in AJAX POST?| JQuery Ajax Post Json Example
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- How to add, edit and delete rows of an HTML table with Jquery?
- Registration form with image upload in MVC using jquery Ajax
- How to make an Inline editable table in MVC using jquery?
- Insert Update Delete Using Jquery Ajax and Modal Popup in Mvc
- [Solved]-How to Upload pdf file using jquery MVC?
- Dynamically creating graphs with jQuery
- Cannot find items in JSON array
- Use jquery to create a multidimensional array
- jquery Pull Down Menu
- How do I abort print?
- A simple hide/show for faqs that saves to cookie
- Disable Hold Box on ie11 W8.1 Touch Device
- Uncaught TypeError: Cannot call method 'list' of undefined
- JQuery with HTML imagemap
- Update options select attributes according to the other select tag with the help of Ajax and Laravel?
- How to get index number inside $.click() of jQuery?
- jQuery keydown keyup function fires every other time
- jQuery: display divs with numbers ranging from/to?
- select divs that are inside a div and with id that starts with mbItem?
- Show busy gif after user clicks on a Link
- How can I insert a prefix for all jQuery selectors?
- jQuery Insertion Element Notation
- Why won't 'this' work?
- Hidden ul elements on load, display on click
- How to disable a button using bootstrap while using jquery window or viewport size?
- jQuery Animation fade in fade out
- jquery carriage return not retained when sent in data-attribute
- jquery slider and mouseover code
- Stopping the Current page from reloading when active
- JQUERY SELECT AJAX
- jQuery ssl issues - why do I see hwcdn.net in the response?
- Identify a child of a <tr>
- jquery validation
- Struggling with JQuery .each() Function
- html5 Canvas display default area in canvas
- How to pass a javascript variable to php using getJSON
- Regex for each object in jquery array
- Improving to class toggling
- jquery ordered list index
- Slide div under button clicked within a list of buttons
- avoid repeating jquery event bindings
- Creating object using modal in rails
- How do you load another page with ajax with a link within ajax loaded content
- Using jquery.calculation.js with dynamically added form fields
- check image has been loaded using jquery
- How get element with jQuery from HTML
- how could I append different values into an array?
- getting which dom element is returned?
- Browser compatibility issue with page logo
- How to hide group heading when child elements not present on user search
- Change div contents on link click
- How to change color by clicking cells
- Form validation before Submit
- Editing submitted data from checkboxes
- How to update value based on other input box dynamically using jQuery?
- How can I move a DOM section including current form field values?
- Use only parts of a string
- Duplicating script and incrementing id names to dynamically add input content
- Javascript set default value on dropdownlist not working
- Laravel data to javascript could this be insecure and an open vulnerability?
- Draggable With Database PHP and MYSQL
- Background image doesn't fit well
- Whats the fastest way to highlight different strings in an html document?
- Cannot add/remove class with jQuery in IE8 and below
- How to limit autocomplete results with devbridge jquery autocomplete
- jQuery: hide element
- Adding a class to a table when a checkbox is checked
- jQuery in PHP, using $_GET
- format the json data with jquery in to a particular format
- Saving Values in LocalStorage onclick?
- getJSON works on Android but Not IOS
- Animations not working on pseudo-elements? IE10
- unchecked checkbox can't be set to be checked by Jquery or Javascript in scala play framework 2.0.4?
- How to Slide down part of element
- How to create a JavaScript range slider with links?
- Trying to make a click animation repeatable
- How to access the textbox value created inside php tag to the ajax call
- How can I make this background become less opaque as the page scrolls down?
- Reloading an external element (via jQuery's .load) without impact on same-named host elements on same page?
- Using multiple forms in HTML
- jQuery API Usage
- jQuery DIV height issues
- How can I share a variable amongst a jQuery event map?
- Name Attribute of Clicked Element
- Animate slideshow horizontally on click
- How to exclude elements with certain class names when triggering JS function calls
- knockout hide all not active elements
- simple jquery trigger help
- Issue on Concatenating Two Select Options val() Using jQuery
- Add Struts 2 select drop down list dynamically using JavaScript/JQuery
- How can you put PHP inside a Javascript?
- how to remove unselected option of select box by jquery
- Using jQuery to change text upon page load without it being obvious to the user
- Use old and new value on Javascript after onChange of Select element
- Remove all values after specific one from array with jquery
- JQuery stop element from fading back in
- jQuery Copy text from one field to another but replacing white spaced with dashes
- Display Kendo datepicker icon on the left
- How can I detect when a text area loses focus and keep it from losing focus when a particular element is clicked?
- addClass to a div with specific attribute
- array of element id with same class
- Rails 6 does not see JS
- Nesting JQuery .click() events
- Show Hide closest element clicked
- Popup - scroll by mouse wheel
- Using jQuery to find if any drop down (out of multiple) has a selected value with index > 0
- Jquery animate on left with z-index
- Efficiency of jQuery $.on() scoping
- jcarousel is not firing event on images
- How to use JQuery plugin on nuxtjs.
- .hide().show() in single event causes rerendering?
- Jquery nextUntil() alternative
- slide image from left to right and reverse back again
- How to bind a function without particular event to dynamically added elements?
- Grabbing Minutes + Hours for Opening / Closing Times
- Update timestamps every 30 seconds using setInterval()
- Global Variables in jquery nested functions?
- How to add some CSS Class through jQuery on scrolling the page
- Convert Form Post to Querystring
- javascript argument get wrong number
- identify malicious file upload in javascript
- JavaScript compact if/else into a single line?
- How to fire a scoped function from a .jsp page?
- How to set the auto width for combo box in Kendo UI?
- show all file names from multiple file input in a single alert
- jQuery delegate and preventDefault()
- HTML to import another HTML file not displaying correctly
- How to limit jQuery searches to a certain area
- Apply Validation on the added form using jquery
- jquery alert plugin , jConfirm
- django checkbox select all by jquery
- Associative arrays in Jquery with Traversing Each Element
- Passing Multiple Variables to a PHP page
- jQuery - Display divs one by one
- Trouble using jQuery post inside non jQuery function
- Select checkbox = to the number of input?
- Laravel 5 - Modal cannot retrieve values of datatable row
- implementing a javascript graph application to the existing admin panel's listing view
- Checkbox will not fire function onLoad of page
- jquery - pattern matching
- Why does my jQuery AJAX function always return false?
- get jquery object from jquery collection
- Pass attributes to method jQuery and Rails
- JQuery populate form depending on select option selected
- jQuery function to change background color not working
- jQuery check how many select elements have selectedIndex !== 0
- submit without refreshing
- Blinking control object in jQuery
- jquery fading in on screen after time
- how to prevent calling a function multiple times in Jquery
- Limit checkboxes checked, include boxes checked on page load
- An easy way to create a JQuery single field confirmation dialogs for a webpage
- Loading EXIF data from currently displayed image with jquery
- jQuery, Google Maps API, a is null, and a different amount of locations markers showing up each reload
- Do React.js and jQuery accomplish the same thing?
- Problems with growing a div in jQuery (relative and absolute divs)