Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart is unknown chart type #86

Closed
graphicsxp opened this issue Oct 10, 2016 · 21 comments
Closed

Chart is unknown chart type #86

graphicsxp opened this issue Oct 10, 2016 · 21 comments

Comments

@graphicsxp
Copy link

graphicsxp commented Oct 10, 2016

After going through a lot of troubles trying to import the angular2-highcharts module in my ionic2 application, I'm now having this error at runtime:

'Chart is unknown chart type'

basically it is raised from initChart.js :

 if (!highchartsService.Highcharts[type]) {
    throw new Error(type + " is unknown chart type.");
}

the highchartsService is an empty object.

Any idea why ?

@Fank
Copy link
Collaborator

Fank commented Oct 10, 2016

Duplicate of #83

@Fank Fank closed this as completed Oct 10, 2016
@graphicsxp
Copy link
Author

graphicsxp commented Oct 10, 2016

well, I don't use systemjs, and I'm doing everything like in the sample (code-wise). If anyone has a solution to make this working with ionic2RC, I'd appreciate some help.

@graphicsxp
Copy link
Author

besides, I believe the module is loaded since the error is raised by the module itself....

@graphicsxp
Copy link
Author

well for the record, I've solved it:

 <script src="build/chart.js"></script> 

needs to be before

 <script src="build/main.js"></script>

in index.html

@easierbycode
Copy link

@graphicsxp did you get this working for angular2-highcharts or @progress/kendo-angular-charts?

@graphicsxp
Copy link
Author

angular2-highcharts.

I'm testing kendo-angular-charts right now actually. It works great when I run it with liveserver but no luck with building for android using aot compiler. This is because kendo-angular is missing the metadata.json file required by aot angular2 compiler. Can't change that since kendo is not opensource....

@easierbycode
Copy link

@graphicsxp I finally got it working too!

there is no chart.js on index.html when using angular2-highcharts w/ ionic2RC, so my solution was to modify rollup.config.js:

commonjs({
      include: [
        'node_modules/angular2-highcharts/**',
        'node_modules/highcharts/highstock.src.js',
        'node_modules/highcharts/highcharts-more.src.js'
      ],
      namedExports: {
        'node_modules/angular2-highcharts/index.js': ['ChartModule', 'Highcharts'],
        'node_modules/highcharts/highstock.src.js': ['Highcharts'],
        'node_modules/highcharts/highcharts-more.src.js': ['HighchartsMore']
      }
    })

.. then, to fix build I added this at the bottom of @types/highcharts/index.d.ts:

declare var HighchartsMore: (H: HighchartsStatic) => HighchartsStatic;

declare module "highcharts/highcharts-more.src" {
    export = HighchartsMore;
}

Here's the component code:

import { Highcharts } from 'angular2-highcharts';
import HighchartsMore from 'highcharts/highcharts-more.src';


HighchartsMore( Highcharts );

@beabri
Copy link

beabri commented Mar 6, 2017

Hi all, it always gives me the error:

schermata 2017-03-01 alle 12 43 21

Here my app.module.ts:

import { ChartModule } from 'angular2-highcharts';

@NgModule({
  imports: [
    ChartModule.forRoot('highcharts')
  ]
})
export class AppModule {
}

My sistemjs.config.js:

    map: {
        'angular2-highcharts': 'npm:angular2-highcharts',
        'highcharts': 'npm:highcharts'
    },
    packages: {
        highcharts: {
            main: './highcharts.js',
            defaultExtension: 'js'
        },
        'angular2-highcharts': {
            main: './index.js',
            defaultExtension: 'js'
        }            
    }

And, inside my component:

import { Component } from '@angular/core';
import { ChartModule } from 'angular2-highcharts';

@Component({
  selector: 'highchart',
  template: '<chart [options]="options">'
})

constructor() {
    this.options = {
        title : { text : 'angular2-highcharts example' },
        series: [{
            name: 's1',
            data: [2,3,5,8,13],
            allowPointSelect: true
        },{
            name: 's2',
            data: [-2,-3,-5,-8,-13],
            allowPointSelect: true
        }]
    };

    console.log(this.options);
} 
options: Object;

What am I missing?

@HuangJian
Copy link

@beabri

I guess I had a similar issue like yours and finally found a solution. Just post it here in case it could help.

The problem is that the angular2-highcharts library needs to inject a static Highcharts instance to the HighchartsService class.
Since we are importing the Highcharts library externally from SystemJS (mine is Webpack), we need to pass the Highcharts variable/instance to the ChartModule module.

So, please try to change your app.module.ts as follow:

import { ChartModule } from 'angular2-highcharts';
import { Highcharts } from 'highcharts';

@NgModule({
  imports: [
    ChartModule.forRoot(Highcharts)
  ]
})
export class AppModule {
}

@jmerazhn
Copy link

Hi @HuangJian
I have problems importing the Highcharts:

ERROR in C:/Users/Josue Meraz/Documents/2017/Udemy/Angular 2 - De cero a experto/Practicas/1. HighchartsApp/src/app/app.module.ts (6,10): Module '"C:/Users/Josue Meraz/Documents/2017/Udemy/Angular 2 - De cero a experto/Practicas/1. HighchartsApp/node_modules/@types/highcharts/index"' has no exported member 'Highcharts'.

@howtimeflies-io
Copy link

Hi @jmerazhn

You don't need to import the Highcharts variable into your project, importing ChartModule is enough (it will load the Highcharts dependency automatically)

import { ChartModule } from 'angular2-highcharts';

If you need the Highcharts variable, please try it this way:

declare let require: any;
const Highcharts = require('../node_modules/highcharts/highcharts.src'); // please modify the relative path as needed

@jmerazhn
Copy link

Hi @howtimeflies-io
I am sorry!

I still have a problem, I do not know what I'm doing wrong.
web
appmodule

@howtimeflies-io
Copy link

Hi @jmerazhn

It seems you are not loading the Highcharts library externally. So angular2-highcharts should take care of it for you.

Is there any error when following the angular2-highcharts instruction?

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ChartModule } from 'angular2-highcharts';
import { App } from './App';

@NgModule({
    imports: [
      BrowserModule, 
      ChartModule.forRoot(require('highcharts'))
    ],
    declarations: [App],
    bootstrap: [App]
})
export class AppModule {}

@jmerazhn
Copy link

@howtimeflies-io
Yes, I have the following problem.
He says he does not recognize 'require'.

require

@howtimeflies-io
Copy link

@jmerazhn

Just add a single line bellow the imports.

declare let require: any;

@jmerazhn
Copy link

Thank you @howtimeflies-io
It's just what was missing! Now what I am going to try is to feed the data from a service rest.

@jmerazhn
Copy link

Hi @howtimeflies-io
When I am doing the project build, it sends me an error with the require variable.
How do you think it can be solved?
ngbuild

@howtimeflies-io
Copy link

Hi @jmerazhn

I have no idea how to fix this issue since it did not happen in my project.
If you can make to tiny project to showcase this issue, maybe we can take some time to help.

@anandraj9497
Copy link

I am facing the same problem. Can't bind to 'options' since it isn't a known property of 'chart'. ("

Could any one please help me to solve this error?

@pscanlon1
Copy link

I solved this with doing following

declare let require: any; // outside of NgModule()

ChartModule.forRoot(require('highcharts'))

@lomo1
Copy link

lomo1 commented Feb 23, 2018

i am using ng-cli 1.6 and have same issue now, any one can help it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants