angular6配置echarts4.x使用echarts-wordcloud

1、安装echarts4.x及echarts-wordcloud

npm install echarts

npm install ngx-echarts

npm install echarts-wordcloud

 

tip:rxjs和rxjs-compat这两个不能少,否则会报object().empty和try-catch错误。

 

2、从node_modules库中引入js库

angular6版本已经不推荐在angular.json里面引入插件的js库,而在tsconfig.json文件中进行配置

3、装载NgxEchartsModule模块

有两种方式使用。

①配全局使用echarts的:

在app.module.ts文件配置

或者有的喜欢share.module.ts配置

import { NgxEchartsModule } from 'ngx-echarts';

②配置局部使用echarts:

在使用到echarts的模块下进行配置

 

4、使用echarts-wordcloud

在使用echarts-wordcloud的组件中初始化的时候引入

ngOnInit() {

require('echarts-wordcloud'); // echarts4.0使用词云的前提必须先加载包

}

 

因为之前已经全局配置echarts,这里就不用再引入echart插件库了,否则:

require('echarts');

require('echarts-wordcloud');

​

5、提示事项

由于echarts-wordcloud官方demo已经很久没有更新了,使用echarts4.x配置echarts-wordcloud的时候,很多人反馈字体没有颜色。

解决办法是:用textStyle 代替 itemStyle 属性。

textStyle: {
            normal: {
                color: function() {
                    return 'rgb(' + [
                        Math.round(Math.random() * 160),
                        Math.round(Math.random() * 160),
                        Math.round(Math.random() * 160)
                    ].join(',') + ')';
                }
            }

参考资料:

https://www.npmjs.com/package/echarts-wordcloud

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Angular 中,要更改 `response.headers.get('X-toyoApp-alert')` 的值,您可以使用 `HttpInterceptor`。拦截器是 Angular 中用于在请求和响应之间添加通用处理逻辑的机制之一。您可以创建一个拦截器来更改 `X-toyoApp-alert` 头的值,然后将其注入您的应用程序中。 以下是如何创建一个拦截器来更改 `X-toyoApp-alert` 头的值的示例代码: ```typescript import { Injectable } from '@angular/core'; import { HttpInterceptor, HttpHandler, HttpRequest, HttpResponse } from '@angular/common/http'; @Injectable() export class MyInterceptor implements HttpInterceptor { intercept(request: HttpRequest<any>, next: HttpHandler) { return next.handle(request).pipe( tap((event) => { if (event instanceof HttpResponse) { const alertHeader = event.headers.get('X-toyoApp-alert'); if (alertHeader) { // 更改头的值 event = event.clone({headers: event.headers.set('X-toyoApp-alert', 'new value')}); } } }) ); } } ``` 在上面的代码中,我们创建了一个名为 `MyInterceptor` 的拦截器,它会拦截所有 HTTP 请求和响应。在 `intercept()` 方法中,我们首先调用 `next.handle(request)` 来继续处理请求。然后,我们使用 RxJS 的 `tap()` 操作符来处理响应。如果响应是 `HttpResponse` 类型,并且包含 `X-toyoApp-alert` 头,我们使用 `clone()` 方法来创建响应的副本,并设置新的头值。 要将拦截器应用于您的应用程序,请在 `AppModule` 中将其提供给 `HTTP_INTERCEPTORS` 标记。例如: ```typescript import { NgModule } from '@angular/core'; import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; import { MyInterceptor } from './my-interceptor'; @NgModule({ imports: [HttpClientModule], providers: [ { provide: HTTP_INTERCEPTORS, useClass: MyInterceptor, multi: true } ] }) export class AppModule { } ``` 在上面的代码中,我们将 `MyInterceptor` 提供给 `HTTP_INTERCEPTORS` 标记,并设置 `multi: true` 选项,以确保它不会覆盖其他拦截器。现在,每当您的应用程序发出 HTTP 请求时,拦截器都会拦截它,并更改 `X-toyoApp-alert` 头的值(如果存在)。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值