简体   繁体   English

如何在angular4中使用fusioncharts?

[英]how to use fusioncharts for with angular4?

I installed with: 我安装了:

npm install fusioncharts

I imported like this: 我这样输入:

 import * as  FusionCharts from  'fusioncharts';

but, when i made a new object like this: 但是,当我制作这样的新对象时:

var fusioncharts = new FusionCharts({
    type: 'radar',
    renderAt: 'chart-container',
    width: '500',
    height: '350',
    dataFormat: 'json'
});

the library try to load http://localhost:4200/fusioncharts.powercharts.js 该库尝试加载http://localhost:4200/fusioncharts.powercharts.js
(this file doesn't exist in this path) (此文件在此路径中不存在)

Anyone knows what I'm doing wrong? 有人知道我在做什么错吗? thanks! 谢谢!

first Install the angular4-fusioncharts package using "npm install angular4-fusioncharts --save" next install "npm install fusioncharts --save" 首先使用“ npm install angular4-fusioncharts --save”安装angular4-fusioncharts软件包,然后再安装“ npm installfusioncharts --save”

import this in your main module 将此导入您的主模块

import * as FusionCharts from 'fusioncharts';
import * as Charts from 'fusioncharts/fusioncharts.charts';
import * as FintTheme from 'fusioncharts/themes/fusioncharts.theme.fint';
import { FusionChartsModule } from 'angular4-fusioncharts';

FusionChartsModule.fcRoot(FusionCharts, Charts, FintTheme);

@NgModule({
declarations: [
    AppComponent
],
imports: [
    BrowserModule,
    FusionChartsModule
],
providers: [],
bootstrap: [AppComponent]
 })
 export class AppModule { }

In your app.component.ts 在您的app.component.ts中

import { Component } from '@angular/core';

 @Component({
   selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
   })
export class AppComponent {
id = 'chart1';
width = 600;
height = 400;
type = 'column2d';
dataFormat = 'json';
dataSource;
title = 'Angular4 FusionCharts Sample';

constructor() {
    this.dataSource = {
        "chart": {
            "caption": "Harry's SuperMart",
            "subCaption": "Top 5 stores in last month by revenue",
            "numberprefix": "$",
            "theme": "fint"
        },
        "data": [
            {
                "label": "Bakersfield Central",
                "value": "880000"
            },
            {
                "label": "Garden Groove harbour",
                "value": "730000"
            },
            {
                "label": "Los Angeles Topanga",
                "value": "590000"
            },
            {
                "label": "Compton-Rancho Dom",
                "value": "520000"
            },
            {
                "label": "Daly City Serramonte",
                "value": "330000"
            }
        ]
    }
   }
 }

In component.html 在component.html中

<fusioncharts
[id]="id"
[width]="width"
[height]="height"
[type]="type"
[dataFormat]="dataFormat"
[dataSource]="dataSource"
></fusioncharts>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM