Open Yalrafih opened 7 years ago
I am using highchart with angular 4 this way:
import { ChartModule } from 'angular2-highcharts';
import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';
import * as highcharts from 'highcharts';
export function highchartsFactory() {
return highcharts;
}
@NgModule({
declarations: []
,
imports: [ ChartModule]
,
providers: [
{
provide: HighchartsStatic,
useFactory: highchartsFactory
}
],
Does this work for you?
I am using Angular CLI as well. So if you are using Systemjs or similar I probably cannot help you.
/edit: removed unneeded part (authentificationservice was from my project)
+1 but with Systemjs. After upgrading to Angular v4.1.3 I am now receiving this error: Unexpected value 'undefined' imported by the module __MyModule__
in reference to ChartModule
from import { ChartModule } from 'angular2-highcharts';
.
it works well with angular-cli following this method. But it fails when i try to load charts and maps together within the same module.
@Wandang
I get "StockChart is unknown chart type." when using your method
Hello It works for me and here an example with drilldown chart. With ANGULAR 4
I just declare the variable "require" and i can used normally. export declare let require: any;
Example:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ChartModule } from 'angular2-highcharts';
import { DrillDownComponent} from './CommonComponents/DrilDown/DrilDown.component';
export declare let require: any;
@NgModule({
declarations: [
AppComponent
,DrillDownComponent
],
imports: [
BrowserModule,
, ChartModule.forRoot(require('highcharts'),
require('highcharts/modules/data'),
require('highcharts/modules/drilldown'))
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
Please provide working example code for integrating with angular 4, Otherwise its of no use for long run.
My last comment was developed with Angular 4
i can confirm @AbelValdez comment does work with angular 4. although it does not follow most plugins common way of use, it does work.
Does this work with Angular 4 and AOT? I have not been able to get that combination to work.
It works for me too with the config from @Wandang (config Angular 4 with CLI) thanks guys !
I got this to work with @Wandang but not @AbelValdez in Angular 4. However, I need to add highstocks too, any ideas how?
Thanks!
zone.js:642 Unhandled Promise rejection: Template parse errors: Can't bind to 'options' since it isn't a known property of 'chart'. (" simple-charts works!
<chart [ERROR ->][options]="options">Can someone tell why I am getting this using angular 4? @Wandang @AbelValdez
@Wandang @AbelValdez ... its working for me. Thanks for the help :)
Do not use require, use @Wandang's solution instead.
require()
is not advisable for a few reasons. One, it will "break" the effectiveness of tree-shaking in webpack 2 and two, it will prevent proper code splitting. source
With @Wandang's solution, you can load easily modules, such as HighchartsMore, BrokenAxis, and Highmaps, inside the factory. Works like a charm here.
import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';`
import * as highcharts from 'highcharts';
import * as highchartsMore from 'highcharts/js/highcharts-more';
import * as brokenAxis from 'highcharts/js/modules/broken-axis';
import * as highmaps from 'highcharts/js/modules/map';
export function highchartsFactory() {
// Initialize addons.
highchartsMore(highcharts);
brokenAxis(highcharts);
highmaps(highcharts);
return highcharts;
}
@NgModule({
declarations: []
,
imports: [ ChartModule]
,
providers: [AuthentificationService,
{
provide: HighchartsStatic,
useFactory: highchartsFactory
}
],
Note that you may get an Highcharts error # 27 in your console when loading a combination of HighchartsMore, Highmaps and Highstock. This is a bug and will be fixed in 5.0.13.
@Jrubzjeknf ahright ahright so I update my code with you review and that's works fine for me
@Jrubzjeknf I am struggling to find out how to import the 3D module correctly. (My goal is to create a 3D scatter plot)
Edit: Found the error. The import was wrong.
Instead of
import * as highcharts3d from 'highcharts/js/highcharts-3d';
I needed to use
import * as highcharts3d from 'highcharts/highcharts-3d';
Old issue below this line
I tried:
import * as highcharts3d from 'highcharts/js/highcharts-3d';
export function highchartsFactory() {
highcharts3d(highcharts);
return highcharts;
}
It compiles fine but the website itself gives me a typeerror:
AppComponent.html:296 ERROR TypeError: this.definition is not a function
which is this line:
<chart [options]="chartOptions"
(load)="saveInstance($event.context)">
</chart>
And chartOptions is the default configuration object from the 3d example:
this.chartOptions = {
chart: {
margin: 100,
type: 'scatter',
options3d: {
enabled: true,
alpha: 10,
beta: 30,
depth: 250,
viewDistance: 5,
fitToPlot: false,
frame: {
bottom: { size: 1, color: 'rgba(0,0,0,0.02)' },
back: { size: 1, color: 'rgba(0,0,0,0.04)' },
side: { size: 1, color: 'rgba(0,0,0,0.06)' }
}
}
},
title: {
text: 'Draggable box'
},
subtitle: {
text: 'Click and drag the plot area to rotate in space'
},
plotOptions: {
scatter: {
width: 10,
height: 10,
depth: 10
}
},
yAxis: {
min: 0,
max: 10,
title: null
},
xAxis: {
min: 0,
max: 10,
gridLineWidth: 1
},
zAxis: {
min: 0,
max: 10,
showFirstLabel: false
},
legend: {
enabled: false
},
series: [{
name: 'Reading',
colorByPoint: true,
data: [[1, 6, 5], [8, 7, 9], [1, 3, 4], [4, 6, 8], [5, 7, 7], [6, 9, 6], [7, 0, 5], [2, 3, 3], [3, 9, 8], [3, 6, 5], [4, 9, 4], [2, 3, 3], [6, 9, 9], [0, 7, 0], [7, 7, 9], [7, 2, 9], [0, 6, 2], [4, 6, 7], [3, 7, 7], [0, 1, 7], [2, 8, 6], [2, 3, 7], [6, 4, 8], [3, 5, 9], [7, 9, 5], [3, 1, 7], [4, 4, 2], [3, 6, 2], [3, 1, 6], [6, 8, 5], [6, 6, 7], [4, 1, 1], [7, 2, 7], [7, 7, 0], [8, 8, 9], [9, 4, 1], [8, 3, 4], [9, 8, 9], [3, 5, 3], [0, 2, 4], [6, 0, 2], [2, 1, 3], [5, 8, 9], [2, 1, 1], [9, 7, 6], [3, 0, 2], [9, 9, 0], [3, 4, 8], [2, 6, 1], [8, 9, 2], [7, 6, 5], [6, 3, 1], [9, 3, 1], [8, 9, 3], [9, 1, 0], [3, 8, 7], [8, 0, 0], [4, 9, 7], [8, 6, 2], [4, 3, 0], [2, 3, 5], [9, 1, 4], [1, 1, 4], [6, 0, 2], [6, 1, 6], [3, 8, 8], [8, 8, 7], [5, 5, 0], [3, 9, 6], [5, 4, 3], [6, 8, 3], [0, 1, 5], [6, 7, 3], [8, 3, 2], [3, 8, 3], [2, 1, 6], [4, 6, 7], [8, 9, 9], [5, 4, 2], [6, 1, 3], [6, 9, 5], [4, 8, 2], [9, 7, 4], [5, 4, 2], [9, 6, 1], [2, 7, 3], [4, 5, 4], [6, 8, 1], [3, 4, 0], [2, 2, 6], [5, 1, 2], [9, 9, 7], [6, 9, 9], [8, 4, 3], [4, 1, 7], [6, 2, 5], [0, 4, 9], [3, 5, 9], [6, 9, 1], [1, 9, 2]]
}]
}
Does'nt work for me with https://github.com/mgechev/angular-seed :(
Does @Jrubzjeknf's solution work with Webpack 3? Using require works, but I don't want to break tree shaking:
// This works
export function highchartsFactory() {
let exportModule = require('highcharts/modules/exporting');
exportModule(highcharts);
return highcharts;
}
@Jrubzjeknf's method:
import * as highcharts from 'highcharts';
// This throws an error
import * as highchartsMore from 'highcharts/js/highcharts-more';
"TS2497: Module '/...' resolves to a non-module entity and cannot being imported using this construct"
Any plan to upgrade to angular4? it is much needed and thanks.