score:4
Drawing a Dotted Line
You don't need to extend the chart, but it would be cleaner to do it that way.
Preview
Script
Chart.types.Line.extend({
name: "LineAlt",
initialize: function () {
Chart.types.Line.prototype.initialize.apply(this, arguments);
var ctx = this.chart.ctx;
var originalBezierCurveTo = ctx.bezierCurveTo;
ctx.bezierCurveTo = function () {
ctx.setLineDash([10, 10]);
originalBezierCurveTo.apply(this, arguments)
}
}
});
...
new Chart(ctx).LineAlt(chartData);
Fiddle - https://jsfiddle.net/ahj6u14e/
Note - the alternative would be to just override bezierCurveTo
using the chart object.
This works because bezierCurveTo
is only used to draw the line. If you wanted to do this for straight lines it wouldn't work because lineTo
is used for other stuff (axis, grid lines...)
Chart.js 2.0 had a borderDash
option when I last checked (see https://stackoverflow.com/a/31428640/360067)
score:6
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
score:7
In Chart.js 2.1+
, use the borderDash
option within your dataset. It takes an array of two numbers. See this codepen
Source: stackoverflow.com
Related Query
- How can I draw dotted line using chartjs?
- How to draw Horizontal line on Bar Chart Chartjs
- Can we draw a Line Chart with both solid and dotted line in it?
- how to draw line graph with line animation from left to right using chartjs?
- ChartJS / Chartjs-plugin-annotation How to draw multiple vertical lines using an array?
- How to draw multiple line on y axis for same x axis in chartjs v2?
- how can i send a list of numbers from views.py to a chartjs file im using for the front?
- How to draw a range label on x axis using chartJS
- Can't Draw Horizontal Line on Graph Using ChartJS Annotation Plugin and Primevue Chart
- Chartjs 3 how to draw a horizontal line starting at a specific yAxis value
- How to draw multiple color bars in a bar chart along a Horizontal Line using chart.js
- How can I shade a portion of a ChartJS line grph=
- How to Draw a line on chart without a plot point using chart.js
- How can I draw a line to the highest datapoint in chart js?
- how to draw dotted line vertical line at 0 postiion in highChart
- Chartjs - how to make line position to vertical center and how to display dotted sharp in the backround?
- how to draw Line chart using chart.js and datalabels should be shown
- Draw stacked horizontal bar chart with Average line using ChartJS
- How can i change the every legend label font color using chart.js version 2.8.0 (spacial line chart)?
- How Can I Get An Instance of a ChartJS Bar Chart Using Angular
- How to run Chart.js samples using source code
- How do I draw horizontal bars with a label using either ChartJS or D3?
- Chart.js: How can I set paddings and draw a background box in a line chart?
- How to add vertical line in bar chart using chartJs and ng2-charts?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Dotted Line in ChartJS
- How to modify chartjs tooltip so i can add customized strings in tooltips
- How to add an on click event to my Line chart using Chart.js
- Display line chart with connected dots using chartJS
- How to Draw Gantt chart using chart js or other libraries
More Query from same tag
- Chart.js data not initially loaded
- GeoChart with nodeJS
- Live Update Callback -> afterTitle with Array via JSON file
- Connect 2 line in chart using chartjs
- ChartJS tooltip when having multiple lines on a time graph
- Ionic Capacitor chart.js showing blank on ios device
- How to hide the tick marks of the axis in react-chartjs-2
- How to ensure that a Chart.js line chart uses all space available on the y-axis?
- How can i loop some specific key in each index json data and put it in dataset: data ? (chart.js)
- How to update ChartJS in a long polling & stop animation stuttering?
- ChartJS remove previous chart when making new one
- Update Chart.js plugin
- automatic Y-axis scale: max is always as 120% of highest value in ChartJS
- How to draw a linear regression line in Chart.js
- ChartJS tooltip scrollbar to prevent data overflow?
- Chart.js Thick label gets replaced by three dots
- line charts is higher that the dataset in Chart.JS
- Not drawing null values using chart.js
- how to show data label on barchart using chart.js in Angular10 project?
- How to color legend in angular-chart.js
- Change legend style from bar to line chart.js 2.4.0
- Chart.js, changing the max height (not w/ canvas) or rounding up rule?
- How can I move chartJs legend left side and change the width and Hight of the chart?
- chart.JS time axis labels should be just in hours format
- How we can draw a circle in bar chart
- Customize Pie Chart Legend in chart.js
- Detecting hover events over parts of a chart using Chart.js
- Chart.js - displaying multiple line charts using multiple labels
- In reactjs doughnut chart, How to reduce the width of the chart
- How to add an extra tick on top of the highest bar in Chart.js v2.9.4 (grace)?