I would like to draw dotted line using chartjs. I did not see any options in creating dotted lines. I feel we need to extend the chartjs to support this. Can some one help me in this?
Lets say you wanted to add 50px of padding to the left side of the chart canvas, you would do: let chart = new Chart(ctx, { type: 'line', data: data, options: { layout: { padding: { left: 50 } } } }); Copied!
For dotted lines use borderDash
and borderCapStyle
. The following example creates a dotted line (3px diameter):
data: {
datasets: [
{
data : data,
borderWidth : 3, // set diameter of dots here
borderColor : '#ccc',
fill : false,
pointRadius : 0,
borderDash : [0,6], // set 'length' of dash/dots to zero and
// space between dots (center to center)
// recommendation: 2x the borderWidth
borderCapStyle : 'round' // this is where the magic happens
}
]
}
Output
Output (better contrast for demonstration)
In Chart.js 2.1+
, use the borderDash
option within your dataset. It takes an array of two numbers. See this codepen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With