Posted in charts
2252
2:42 am, April 5, 2023
 

chart js line chart dont show below 0 and add axis labels

Now we take the chart js chart and add some axis labels on x and y using the same options values.

This will also add axis labels to the chart on the x and y axis

Javascript

	options: {
		scales: {
			yAxes: [{
				ticks: {
					beginAtZero: true
				},
				scaleLabel: {
					display: true,
					labelString: 'This is my Y Label'
				}				
			}],
			xAxes: [{
				scaleLabel: {
					display: true,
					labelString: 'My X Label'
				}				
			}]
		}
	}

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
				},
				scaleLabel: {
					display: true,
					labelString: 'This is my Y Label'
				}				
			}],
			xAxes: [{
				scaleLabel: {
					display: true,
					labelString: 'My X Label'
				}				
			}]
		}
	}
});

View Statistics
This Week
27
This Month
232
This Year
596

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
I believe that in order to better your knowledge base, it takes a lot of failing in order to succeed. I don't consider anything a failure as long as you get back up and you learn from your own mistakes.
Unknown
Random CSS Property

all

The all shorthand CSS property resets all of an element's properties except unicode-bidi, direction, and CSS Custom Properties. It can set properties to their initial or inherited values, or to the values specified in another stylesheet origin.
all css reference