Angular9上的ng2图表不响应式。
创始人
2024-10-22 16:30:39
0

使用ngx-charts库代替ng2-charts,并在组件中设置chartOptions中的responsive属性为true,以使图表成为响应式的。

代码示例:

  1. 安装ngx-charts库:
npm install @swimlane/ngx-charts --save
  1. 导入需要的模块和组件:
import { NgModule } from '@angular/core';
import { NgxChartsModule } from '@swimlane/ngx-charts';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
  1. 在组件中设置chartOptions属性:
import { Component } from '@angular/core';
import { single } from './data'; // 导入图表数据

@Component({
  selector: 'app-root',
  template: '',
})
export class AppComponent {
  data = single; // 设置图表数据
  colorScheme = 'vivid'; // 设置颜色方案
  showLegend = true; // 显示图例
  showXAxis = true; // 显示X轴
  showYAxis = true; // 显示Y轴
  xAxisLabel = 'Country'; // 设置X轴标签
  yAxisLabel = 'Population'; // 设置Y轴标签
  curve = shape.curveBasis; // 设置线段样式
  tooltipDisabled = false; // 禁用tooltip
  gradient = false; // 禁用渐变色
  animations = true; // 开启动画
}

以上代码将创建一个包含线

相关内容

热门资讯

透视工具!wejoker黑侠辅... 透视工具!wejoker黑侠辅助器(透视)wepoker有没有机器人(竟然一直都是有挂)-哔哩哔哩1...
透视神器!hhpoker辅助挂... 透视神器!hhpoker辅助挂(透视)hhpoker到底可以作必弊码(原来一直总是有挂)-哔哩哔哩1...
透视神器!模拟器打开hhpok... 透视神器!模拟器打开hhpoker(透视)hhpoker免费透视脚本(切实有透视)-哔哩哔哩1、首先...
透视攻略!hh poker软件... 透视攻略!hh poker软件(透视)hhpoker德州机器人(原来一直总是有透视)-哔哩哔哩1、很...
透视软件!潮汕激k辅助(辅助)... 透视软件!潮汕激k辅助(辅助)新九五辅助微信脚本(其实存在有挂)-哔哩哔哩一、新九五辅助微信脚本可以...
透视脚本!aapoker脚本怎... 透视脚本!aapoker脚本怎么用(透视)aapoker怎么拿好牌(一贯一直都是有透视)-哔哩哔哩1...
透视攻略!hhpoker到底可... 透视攻略!hhpoker到底可以作必弊码(透视)德扑HHpoker有挂吗(一贯一直总是有辅助器)-哔...
透视app!德州透视插件(透视... 透视app!德州透视插件(透视)hhpoker辅助器(真是有透视)-哔哩哔哩1、在德州透视插件插件功...
透视攻略!拱趴大菠萝有挂吗(透... 透视攻略!拱趴大菠萝有挂吗(透视)pokemmo手机版透视脚本(总是是有辅助器)-哔哩哔哩1、不需要...
透视脚本!欢聚水鱼脚本(辅助)... 您好,jj斗地主捕鱼辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...