Posted in
3210
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
101
This Month
398
This Year
1555
Add Comment
Other Items in charts
Related Search Terms
Other Categories in Code
alpine js apps c css factorio font awesome images linux quick modals sqlite site bugs site updates slick slider sliders testing windows apps apache api apps asp bat bootstrap bootstrap templates charts cookies core css css filters css grid design elements docker domains emoji fancybox fonts foundation framework gimp git html icons ideas image formatting images javascript javascript functions jquery js linux mac misc modals mysql nginx node php php errors php function php functions php simple html dom pi400 python react regex sections simple_html_dom simplepie php site bugs site documentation slick slider sql sqlite ssh sublime svg svg css templates tools virtual box vscode vue webdev windows windows 11 windows commands wordpress