gevgeny / angular2-highcharts

:bar_chart: :chart_with_upwards_trend: Highcharts for your Angular project
MIT License
380 stars 113 forks source link

[Suggest] Documentation update #156

Open fr4ngus opened 7 years ago

fr4ngus commented 7 years ago

Hi, Thank you for the great library. Just for people that using AOT compilation (typically people that use angular-cli), you have to add the following code to your AppModule in order to work:

In your AppModule:

import {HighchartsStatic} from 'angular2-highcharts/dist/HighchartsService';
import {ChartModule} from "angular2-highcharts";

export function highchartsFactory() {
  return require('highcharts');
}

@NgModule({
   providers:[
   ...
   {
      provide: HighchartsStatic,
      useFactory: highchartsFactory
    },
    ....
]}

In the module where you use the chart directive:


@NgModule({
   imports: [
     ChartModule
   ],
 ]}

You could also declare as a singleton (ShareModule)

Thank you !

gevgeny commented 7 years ago

Is it to avoid the ERROR in Error encountered resolving symbol values statically. Calling function 'ChartModule', function calls are not supported. ?

fr4ngus commented 7 years ago

Yep

gevgeny commented 7 years ago

Yea, would be great. But HighchartsService supposed to be private part of the lib. Are there any simplier approach to achieve this ? I would change something in the lib if it is necessary

jessenic commented 7 years ago

How would you load Highcharts modules with this solution? Modules like highcharts/modules/solid-gauge.

Edit: This seems to work for exporting, and for solid gauge:

export function highchartsFactory() {
    var hc = require('highcharts');
    var hcm = require('highcharts/highcharts-more');
    var exp = require('highcharts/modules/exporting');
    var sg = require('highcharts/modules/solid-gauge');

    hcm(hc);
    exp(hc);
    sg(hc);
    return hc;
}

(Added highcharts-more to make solid gauge work)

gevgeny commented 7 years ago

@jessenic should work, but my idea was to hide how modules initialises: module(hc). It is already implemented in the wrapper: https://github.com/gevgeny/angular2-highcharts/blob/master/src/index.ts#L25

ChrisMeeusen commented 7 years ago

I know this issue is marked closed but I'm still having issues on my rollup. Here is the output:

'ChartModule' is not exported by 'node_modules\angular2-highcharts\dist\index.js'

'ChartModule' is not exported by 'node_modules\angular2-highcharts\dist\index.js'

'HighchartsStatic' is not exported by 'node_modules\angular2-highcharts\dist\HighchartsService.js'

Error: 'HighchartsStatic' is not exported by node_modules\angular2-highcharts\dist\HighchartsService.js

Im using
"@angular/compiler-cli": "2.4.4", "rollup": "^0.41.4", "rollup-plugin-commonjs": "^7.0.0", "rollup-plugin-node-resolve": "^2.0.0", "rollup-plugin-uglify": "^1.0.1", "@types/highcharts": "4.2.37", "angular2-highcharts": "^0.5.5",

What versions of these dependencies did you have success with @fr4ngus ?

pequet commented 7 years ago

thank you @fr4ngus. solved my "Error encountered resolving symbol values statically" problem that appeared mysteriously after an upgrade