Posted in
3785
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
113
This Month
332
This Year
1932
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