score:5
Accepted answer
Knowing where you should go, you can now edit the
Instead of editing all the chart and the Rectangle as in the duplicate, you should do it only for each bar you want to display with dashed lines.
If you take a look at the console (console.log(myChart)
provides you a lot of info if you dare go deep in the object), you will see that every bar is instancied in myChart.config.data.datasets[0]._meta[0].data[
x
]
,
x
being the xth bar of the dataset.
Knowing where you should go, you can now edit the
.draw()
method.
Here is a simple function you can use to make it work :
function dashedBorder(chart, dataset, data, dash) {
// edit the .draw() function
chart.config.data.datasets[dataset]._meta[0].data[data].draw = function() {
chart.chart.ctx.setLineDash(dash);
Chart.elements.Rectangle.prototype.draw.apply(this, arguments);
// put the line style back to the default value
chart.chart.ctx.setLineDash([1,0]);
}
}
You can see the result in this jsFiddle.
Source: stackoverflow.com
Related Query
- How to customize border style on Chart.js
- How to style a pie chart in chart js? I want to change the border color, border width and give them shadow
- How Can customize chartjs doughnut chart border and tooltip
- How to remove border from stacked column chart in Chartkick - Chart.js
- how to customize tool tip while mouse go over bars on Chart js bar chart
- How to use segment property to color line / border color based on value in chart js?
- How to customize chart js Bar chart shape?
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- How can I style scale numbers in a Polar Area chart (chart.js)
- How to customize tooltip on mouse hover of a polar area chart of Angular Charts
- How make border radius for chart area chart.js?
- How to print a chart rendered by code
- How to customize chart using chartJs?
- how to change point style legend to diamond in chart js
- How can I remove the white border from Chart.js pie chart when all legends are hidden?
- How do I destroy/update Chart Data in this chart.js code example?
- How to customize Data Labels of area chart on ChartJS?
- How to run Chart.js samples using source code
- how to not repeat code while creating multiple charts in chart js
- How to add text inside the doughnut chart using Chart.js?
- How to clear a chart from a canvas so that hover events cannot be triggered?
- Chart.js - How to set a line chart dataset as disabled on load
- chart js 2 how to set bar width
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How can I make two of my lines in Chart JS thicker
- How to prevent first/last bars from being cut off in a chart with time scale
- How set color family to pie chart in chart.js
- How do I customize y-axis labels on a Chart.js line chart?
- Chart.js Bar Chart - how to chart bars from 0
More Query from same tag
- Line Chart Js x-axis values all 0 on React
- Setting Common labels and background color common for all the charts in ChartJs
- Getting Error regarding :Cannot read property 'length' of undefined
- Created an onclick function to remove data from a line chart in ChartsJs, but getting "Cannot read property 'data' of undefined" error
- How can I make streaming chart with react?
- Android WebView HTML5 canvas error
- how labels in chartjs can make data invisible
- Floating clone does not show in chrome if dragged element contains a chartjs component
- chart.js bar chart datalabel vanishes on hovering over chart
- ChartJS donut chart clipping the edges
- How to shrink the height and increase the line width of a custom Chartjs horizontal line?
- Stacked Mixed Horizontal Bar Chart in Charts.Js Axes Positioning
- Chart.js stacked line chart with differently styled sections
- Chartjs small offset on top
- Chart.Js is keeping old data after AJAX call
- How to place extra text on canvas (not using HTML) beside chart?
- ng2-charts: Datalabels values are not shown in my grapghs
- Issue with int numbers using chart.js
- How to set lower and upper bound in react react-chartjs-2?
- Return values from nested array
- Display data label (legend) in line-chart using chartjs
- How does the chartjs line look start to be greater than 0
- How to add margin bottom in Tittle ChartJS
- Hover event in graph Chart.js
- ChartJS AJAX load labels and data
- Automatic colors assignment in chart.js 2.x doesn't work anymore, used to work in v. 1.x
- How to achieve the best possible performance with mutable data and real-time charts in React?
- Values above points - chart.js
- How to create logarithmic scale in chart.js with normal numbers?
- ChartJS Recreate Chart