Angular 可视化库选择 ngx-chart 解决折线图变曲

2020-02-19  本文已影响0人  咖A喱
  1. 和angular的绑定属性更搭配,语法上看起来很舒适
  2. 库表基本上满足需求,当然也可以自己在库的基础上再造轮子
  3. 在对比中最让我不舒适的是其它几个库都没有把图表数据单独作为一个元数据,这对于动态生成图表也太不友好了把!
  4. 在没有仔细对比的情况下,发现ngx-charts比较惊喜的是交互页面,和能根据数据自动设置xy轴轴标的数据,感觉很友好
<ngx-charts-line-chart
  [view]="view"
  [scheme]="colorScheme"
  [results]="multi"
  [xAxis]="xAxis"
  [yAxis]="yAxis"
  timeline="0"
  [curve]="curveFunc"
>
</ngx-charts-line-chart>
import { Component, OnInit } from '@angular/core';
import * as shape from 'd3-shape';

@Component({
  selector: 'app-line-chart',
  templateUrl: './line-chart.component.html',
  styleUrls: ['./line-chart.component.scss']
})
export class LineChartComponent implements OnInit{
  multi: any[];
  view: any[] = [700, 300];

  // options

  xAxis = true;
  yAxis = true;

  colorScheme = {
    domain: ['#5AA454', '#E44D25', '#CFC0BB', '#7aa3e5', '#a8385d', '#aae3f5']
  };
//绑定cruve属性
  curveFunc = shape.curveCardinal;

  constructor() {
  }

  ngOnInit(): void {
    this.multi = [
      {
        name: 'DSO',
        series: [
          {
            name: '06.01',
            value: 128
          },
          {
            name: '06.15',
            value: 108
          },
          {
            name: '07.01',
            value: 118
          }, {
            name: '07.15',
            value: 110
          }, {
            name: '08.01',
            value: 100
          }, {
            name: '08.15',
            value: 176
          }, {
            name: '09.01',
            value: 140
          },
        ]
      },
    ]
  }

}

更新于几个小时后:

上一篇 下一篇

猜你喜欢

热点阅读