Posted in charts
2534
1:37 am, April 5, 2023
 

chart js line chart dont show below 0

had an issue where the chart was displaying values in the negative, and wanted to start the chart at 0 and no go below. the additional option fixed this issue. 

Javascript

	options: {
		scales: {
			yAxes: [{
				ticks: {
					beginAtZero: true
				}
			}]
		}
	}

HTML

<canvas id="myChart" style="width:100%;max-width:700px"></canvas>

Scripts

<script  
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js">  
</script>

Javascript

const xValues = ["1","2","3"]; 
const yValues = ["5.51","10.21","1.23"]; 

  
new Chart("myChart", {  
	type: "line",  
	data: {  
	labels: xValues,  
	datasets: [{  
		label: "Share Price",
		backgroundColor:"rgba(255, 210, 0,1.0)",  
		borderColor: "rgba(0,0,255,0.1)",  
		data: yValues
	}]  
	},  
	options: {
		scales: {
			yAxes: [{
				ticks: {
					beginAtZero: true
				}
			}]
		}
	}
});

View Statistics
This Week
28
This Month
218
This Year
681

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
Our brains are wired to find things we are looking for - if your always cynical or waiting for things to go wrong, then your life will reflect that. On the other hand, having a positive outlook on life will bring you joy and provide you with inspiration when you least expect it ☀️🍉🌴
Unknown
Random CSS Property

font-variation-settings

The font-variation-settings CSS property provides low-level control over variable font characteristics, by specifying the four letter axis names of the characteristics you want to vary, along with their values.
font-variation-settings css reference