score:3
First of all, you need to extends Chart.js with the extend you mentionned in your post, like this : (using @jbman223 snippet)
// Extend chart.js with a new type of chart
Chart.types.Line.extend({
name: "LineWithLine",
initialize: function () {
Chart.types.Line.prototype.initialize.apply(this, arguments);
},
draw: function () {
Chart.types.Line.prototype.draw.apply(this, arguments);
// Needs to be set with angular-chart options
var lineAtIndex = 2;
var point = this.datasets[0].points[lineAtIndex]
var scale = this.scale
console.log(this);
// draw line
this.chart.ctx.beginPath();
this.chart.ctx.moveTo(scale.startPoint+12, point.y);
this.chart.ctx.strokeStyle = '#ff0000';
this.chart.ctx.lineTo(this.chart.width, point.y);
this.chart.ctx.stroke();
// write TODAY
this.chart.ctx.textAlign = 'center';
this.chart.ctx.fillText("TODAY", scale.startPoint + 35, point.y+10);
}
});
Then, we have to link this new Chart type with angular-chart. Unfortunately, it is a high level of abstraction library, so there is no built-in feature for that. So, the only way I have found to do that so far is to modify angular-chart.js by adding a line in the config :
return angular.module('chart.js', [])
.provider('ChartJs', ChartJsProvider)
.factory('ChartJsFactory', ['ChartJs', '$timeout', ChartJsFactory])
//...
.directive('chartLinebis', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('LineWithLine'); }]);
Finally, call angular-chart with your new chart label :
<canvas class="chart chart-linebis" chart-data="data" chart-labels="labels" chart-legend="true" chart-series="series"></canvas>
Note that it is very important that the js imports respect this order : chart.js -> myExtend.js -> angular-chart.js
JSFiddle (disclaimer : I included angular-chart.js in the middle of the snippet for import order purpose)
Source: stackoverflow.com
Related Query
- Angular 2 ng2-charts donut add horizontal line
- Draw horizontal line on chart in chart.js on v2
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How to add an on click event to my Line chart using Chart.js
- How to add second Y-axis for Bar and Line chart in Chart.js?
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- Draw a horizontal and vertical line on mouse hover in chart js
- How to draw Horizontal line on Bar Chart Chartjs
- How to add gradient background to Line Chart [vue-chart.js]
- Add horizontal Line to my chart.js Barchart
- How to add a horizontal line at a specific point in chart.js when hovering?
- Add a text as tooltip for each point on a line chart
- In Stacked horizontal bar chart how to remove the vertical line in Chart.js?
- How to add title inside doughnut chart in Angular Chart?
- How to add area with break on line chart with fill color
- Angular-chart / line chart with multiple horizontal lines (margins)
- angular-chart add horizontal line
- Add data to line chart using chart.js
- chart.js add second line in a Line chart that starts from end of first line
- add info for points in line chart (js)
- Chart.js horizontal line chart or modified horizontal bar chart
- change space between horizontal (grid) lines for line chart
- How to sort XY line chart tooltip items based on value and add thousands separators?
- Chart.js - Horizontal line on Bar chart interferes with tooltip
- How can I add a euro sign (€) to all tooltips in my chart js line chart
- Chart.js - draw horizontal line in Bar Chart (type bar)
- ChartJS 2.9.4 can't overlay line data on Horizontal Bar chart
- How to add new dataset in line chart of chart.js by iterating over dictionary in JavaScript?
- Dynamically update value for horizontal line in annotation plugin for Chart.js in Angular 5
- Remove top horizontal line in a horizontal bar chart (Chart.js 2)
More Query from same tag
- Chart.js not showing in Android 8.0/Android O
- Chartjs - custom y axis range
- How to set same borderColor and backgroundColor in chartjs javascript
- Is it Possible to get the base 64 of graph without showing it on page / canvas (Graph.Js)
- ChartJS (Radar) - Set base tick position for "0" value
- Chart.js / HTML Canvas - move line
- chart js chart bar chart not showing data from 0
- Zoom chartjs with many X values
- Resizable/Expendable box annotation in ChartJs
- Custom Tooltips On Line Chart Using Chart.js
- Using chart.js inside node.js
- Chart.js doughnut chart tooltip size?
- ng2-Chart not working with newly created angular 10 project
- How to display large amount of information properly without cramping too much in Chart.js
- How to hide / not draw bars with 0 / null / undefined values?
- Values on Y-axis disappear (hide under labels)
- How to draw multiple line on y axis for same x axis in chartjs v2?
- How to fix bars in Chart.js with long labels
- ChartJS - Bottom labels displayed vertically
- Chart.js - get base 64 encoded string as variable
- Add background text in ChartJS
- Setting Limits on Chart.JS
- Plot a multi-line graph from grouped JSON object using Charts.js
- Chart.js bubble chart pointStyle not working
- How to disable converting decimal number to exponential?
- Wkhtmltopdf does not render Chart.JS 2.5.0 graph
- Getting (X,Y) point on mouse click on chart
- How to hide the legend in chart.js in a react project?
- ChartJS - ignore labels
- Reference external JS method in Chart.js callback using Chartjs.ror