Charts
It's easy to get started with Chart.js. All that's required is the script included in your page
along with a
single <canvas> node to render the chart. Chartjs files included in /libcommon/plugins/charts/chart.min.js
Bar Chart
Example
<!-- HTML content ---> <canvas id="myChart" height="100""></canvas> <!-- Chartjs initialisation in javascript --->var myChart = new Chart(ctx, { type: 'bar', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], backgroundColor: [ 'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)' ], borderColor: [ 'rgba(255,99,132,1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)' ], borderWidth: 1 }] }, options: { scales: { yAxes: [{ ticks: { beginAtZero: true } }] } } });
Line Chart
Example
<!-- HTML Content -->
<canvas id="line-chart" height="125"></canvas>
<!-- Chartjs initialisation -->
<script type="text/javascript">
$(document).ready(function () {
new Chart(document.getElementById("line-chart"), {
type: 'line',
data: {
labels: [1500, 1600, 1700, 1750, 1800, 1850, 1900, 1950, 1999, 2050],
datasets: [{
data: [86, 114, 106, 106, 107, 111, 133, 221, 783, 2478],
label: "Africa",
borderColor: "#3e95cd",
fill: false
}, {
data: [282, 350, 411, 502, 635, 809, 947, 1402, 3700, 5267],
label: "Asia",
borderColor: "#8e5ea2",
fill: false
}, {
data: [168, 170, 178, 190, 203, 276, 408, 547, 675, 734],
label: "Europe",
borderColor: "#3cba9f",
fill: false
}, {
data: [40, 20, 10, 16, 24, 38, 74, 167, 508, 784],
label: "Latin America",
borderColor: "#e8c3b9",
fill: false
}, {
data: [6, 3, 2, 2, 7, 26, 82, 172, 312, 433],
label: "North America",
borderColor: "#c45850",
fill: false
}
]
},
options: {
title: {
display: true,
text: 'World population per region (in millions)'
}
}
});
});
</script>
Pie Chart
<!-- HTML Contents --> <canvas id="pie-chart" height="125"></canvas> <!-- Chartjs initialisation --><script type="text/javascript"> $(document).ready(function () { new Chart(document.getElementById("pie-chart"), { type: 'pie', data: { labels: ["Africa", "Asia", "Europe", "Latin America", "North America"], datasets: [{ label: "Population (millions)", backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"], data: [2478,5267,734,784,433] }] }, options: { title: { display: true, text: 'Predicted world population (millions) in 2050' } } }); }); </scipt>
Grouped Bar Chart
Example
<!-- HTML Contents --> <canvas id="bar-chart-grouped" height="100"></canvas> <!-- Chartjs initialisation --><script type="text/javascript"> $(document).ready(function(){ new Chart(document.getElementById("bar-chart-grouped"), { type: 'bar', data: { labels: ["1900", "1950", "1999", "2050"], datasets: [ { label: "Africa", backgroundColor: "#3e95cd", data: [133, 221, 783, 2478] }, { label: "Europe", backgroundColor: "#8e5ea2", data: [408, 547, 675, 734] } ] }, options: { title: { display: true, text: 'Population growth (millions)' } } }); }); </script>
For further details and options about chartjs,
click here