score:5
Accepted answer
You could also extract the wrap to a standalone function that will take Highcharts as its parameter. Then all you need to do is to import and initialize it with the Highcharts
.
//customWrap.ts
export default function(Highcharts) {
const H = Highcharts;
H.wrap(H.Chart.prototype, "getCSV", function(proceed, useLocalDecimalPoint) {
// Run the original proceed method
let result = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
result += '\n"My source 1","My source 2","My source 3"';
return result;
});
}
//app.component.ts
import { Component } from "@angular/core";
import * as Highcharts from 'highcharts';
import HC_exporting from 'highcharts/modules/exporting'
import HC_exportData from 'highcharts/modules/export-data';
import customWrap from './customWrap';
HC_exporting(Highcharts);
HC_exportData(Highcharts);
customWrap(Highcharts);
...
Live demo: https://stackblitz.com/edit/highcharts-angular-basic-line-1jommb?file=src/app/app.component.ts
score:0
OK, finally I manage to get the wrap method working for the getCSV function by adding this in my ngOnInit:
Highcharts.wrap(Highcharts.Chart.prototype, 'getCSV', function(proceed, useLocalDecimalPoint) {
let result = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
result += '\nHello world!';
return result;
});
Beware of two mistakes I made that cost me a couple of hours to find:
- Initially I pass Highcharts.chart.prototype as the first parameter (note the lower case in chart), this didn't raise any error on the client side, but it wasn't overriding the getCSV function.
- Make sure not to use array notation when defining the function you pass as third parameter, as that will change the scope of this and make your proceed.apply call to fail.
This code will fail:
Highcharts.wrap(Highcharts.Chart.prototype, 'getCSV', (proceed, useLocalDecimalPoint) => {
// This will fail
let result = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
return result;
});
Source: stackoverflow.com
Related Query
- Extending highcharts in Angular
- Rendering Highcharts using Angular js Directives
- How to use highcharts with angular 5?
- Getting error while using highcharts in Angular 7
- Angular HighCharts ParlimentChart is not working
- How to fix "Property 'type' is missing in type but required in type 'SeriesXrangeOptions'" in angular highcharts module
- Highcharts instance created in which Angular life cycle hook
- Highcharts Angular with API data
- Highcharts spans beyond bootstrap column width when implemented as an angular directive
- How to structure Angular with Highcharts and lots of dynamic data
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- How do I use an Highcharts Solid Gauge in angular 6 with typescript?
- Angular Highcharts - How to enable noData options and update it dynamically
- Angular JS - "Error: [$interpolate:interr] Can't interpolate:" when using Highcharts
- Highcharts - Global configuration with common code and unique data & Headings
- How to enable noData with highcharts and angular
- Explanation of why I need to wrap a highcharts jquery event in an angular $timeout to access properties
- Add custom buttons in Angular Highcharts Line Chart
- Getting "Highcharts error #17" when creating histogram (using Highcharts with Angular 6)
- How to get the Div id of charts in highcharts on click of it in angular 6
- TreeMap chart of Highcharts in Angular
- Angular Highcharts Custom Legend Label In Area Chart
- How to remove the value and number labels from Highcharts angular gauge
- Getting Highcharts tooltip to return an angular directive?
- HighCharts Stock Chart error code 18
- Highcharts / Highmaps with Angular - Cannot run demo
- Angular Highcharts list of charts with ng-repeat
- highcharts change rendered image source on click
- Angular highcharts problem showing week number
- How to set 'lang' property in Highcharts using Angular JS?
More Query from same tag
- highcharts y axis value display left
- Highcharts X-Axis value not completely displayed
- Is it possible to use boost-canvas without enable WebGL in highcharts (current version 9.0.1)?
- Highchart Download Multiple graph on individual page
- Why .html() doesn't work with SVG selectors using jquery ?
- Dynamic high chart not rendering in MVC C#
- Highstock giving error 15
- Highmaps border color of region
- Show N/A in datalabels, when value is null - Highcharts
- Highchart - xAxis values are to close
- How to display a separating line in Highcharts exporting menu?
- HighChart- Wrong Datetime in the X-Axis for Live Chart
- Update Stockchart yAxis Labels Changes Positions and Label Precision
- Correct approach to apply HTML style in x-axis title
- Parsing Data From HTML Table
- Highcharts: How to link legend to categories rather than to bar series?
- How to use a react component as the label in Highcharts?
- Highstock on load graph displays just one point
- Defaults for Highcharts graphs
- How to sort the items within each stacking column?
- Highcharts - margins update on window resize
- How to change the theme of a Highstock graph with a button?
- how can we set different colors to highcharts-default-patterns?
- Add dataLabel to Area chart in Highcharts.js
- how do I pass the Ajax response data in my highcharts
- Rounded edges Gauge with Highcharts.js
- Decimal values for yAxis categories in Highcharts
- Convert Javascript Object to array of arrays with two values
- Highstock dataGrouping option
- TypeError: Cannot read property 'nodeName' of null