iT邦幫忙

2021 iThome 鐵人賽

DAY 19
1
自我挑戰組

Angular+Spring Boot API 處理股市資料系列 第 19

Angular視覺化套件(Day19)

當我們初步了解Angular的框架後,接著我要介紹一套視覺化套件-ZingChart

ZingChart is a self-contained, dependency-free library that’s compatible with all browsers. We >are dedicated to shipping quality commercial software for your web application.

self-contained:

The library is totally contained. This means the entire state, data, and configuration of any >chart can be saved as a JSON packet. This single source of truth makes it very easy to pass >around chart information in an application.

ZingChart已經把library包含進去了~

Dependency Free:

The library has ZERO non-native browser dependencies. This allows for strong backwards >compatibility and easy integration across any web platform.

相容性高、相當容易在平台之間移轉


ZingChart不但在各種框架下都有支援,當然也包括Angular囉!

zingchart-angular:

zingchart-angular is an Angular Typescript directive to allow ZingChart to work dynamically >with data. Quickly add charts to your Angular application with our ZingChart component. This >guide assumes some basic working knowledge of Angular.

zingchart為Angular準備的ts組件

安裝方式如下



npm install zingchart-angular --legacy-peer-deps 

接著我們在app.module.ts引入這個模組


import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ZingchartAngularModule } from 'zingchart-angular';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

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

在component裡面新增他的設定屬性 app.component.ts


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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  config:zingchart.graphset = {
    type: 'line',
    series: [{
      values: [3,6,4,6,4,6,4,6]
    }],
  };
}

最後在html模板上插入zingchart-angular


<zingchart-angular [config]="config" [height]="500"></zingchart-angular>

儲存後就可以看到頁面show出

https://ithelp.ithome.com.tw/upload/images/20211004/20138857B1X1pv6DG9.png

更多ZingChart套件的使用方式,讓我們之後再繼續說明吧!


上一篇
Angular建立專案(三)(Day18)
下一篇
Angular Stock實作流程說明(Day20)
系列文
Angular+Spring Boot API 處理股市資料32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
Yori
iT邦新手 5 級 ‧ 2022-03-07 14:18:27

安裝zingchartz發生了以下問題,請問有解決的辦法嗎

https://ithelp.ithome.com.tw/upload/images/20220307/201465862o4kYkpPIw.png

Yori iT邦新手 5 級 ‧ 2022-03-07 14:26:01 檢舉

找到問題了
要手動去zing-angular新增zingchart

讚讚喔~~

我要留言

立即登入留言