Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Chart.js library for creating charts in my project. I want to set the y-axis minimum value to zero, but on doing so the second dataset starts after after the end of first dataset.

What I have tried:

Code 1:
<pre><html>
<head>
<script src="Chart.bundle.js"></script>
</head>

<body>

<div class="dvNWwise" style="width: 350px; height: 300px;">
	<canvas id="cvNWwise" style="width: 350px; height: 300px;"></canvas>
</div>

<script type="text/javascript">  
var ctx_cvNWwise = document.getElementById('cvNWwise').getContext('2d'); 
var chrt_cvNWwise = new Chart(ctx_cvNWwise, { 
type: 'bar', 
data: { 
	labels: ['NW-1','NW-2'], 
	datasets: [ 
		{label: 'Total TID', backgroundColor: '#B3E5FC', borderColor: '#03A9F4', borderWidth: 1, data: [12028,8885] }, 
		{label: 'Active TID', backgroundColor: '#CCFF90', borderColor: '#76FF03', borderWidth: 1, data: [8280,6090] }
	] }, 
options: { 
	responsive: true, legend: { position: 'bottom'}, 
	title: {display: true,text: 'Network wise Active Terminals (Total Terminals: 20913)'} 
 } 
 }); 
 </script>

</body>
</html>

Output is proper like this one-
Image 1

Code 2:
<html>
<head>
<script src="Chart.bundle.js"></script>
</head>

<body>

<div class="dvNWwise" style="width: 350px; height: 300px;">
	<canvas id="cvNWwise" style="width: 350px; height: 300px;"></canvas>
</div>

<script type="text/javascript">  
var ctx_cvNWwise = document.getElementById('cvNWwise').getContext('2d'); 
var chrt_cvNWwise = new Chart(ctx_cvNWwise, { 
type: 'bar', 
data: { 
	labels: ['NW-1','NW-2'], 
	datasets: [ 
		{label: 'Total TID', backgroundColor: '#B3E5FC', borderColor: '#03A9F4', borderWidth: 1, data: [12028,8885] }, 
		{label: 'Active TID', backgroundColor: '#CCFF90', borderColor: '#76FF03', borderWidth: 1, data: [8280,6090] }
	] }, 
options: { 
	responsive: true, legend: { position: 'bottom'}, 
	title: {display: true,text: 'Network wise Active Terminals (Total Terminals: 20913)'} ,
	scales:{ yAxes: [{display:true, stacked:true, ticks: {min: 0}} ] }
 } 
 }); 
 </script>

 </body>
</html>

In the Output second data set distorts, second dataset is starting after first dataset.
Image 2


I need help with the second chart.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900