改变 ngx-echarts 图表的颜色

huangapple go评论61阅读模式
英文:

Changing colors of ngx-echarts charts

问题

如何更改ngx-echarts中所有类型图表的颜色?

我已经尝试过(HTML):<div echarts [options]="chartOption" [theme]="colorScheme" class="demo-chart"></div>

(TypeScript):

colorScheme = {
    domain: [
        '#2FDF75',
        '#246EB9',
        '#BCD3F2',
        '#323031',
        '#FBFFF1',
        '#CCFF90',
        '#FFFF8D',
        '#FF9E80'
    ]
};

颜色没有改变。我担心我的自定义主题格式可能不正确。我找不到关于如何轻松更改图表颜色的文档。

英文:

How to change the colors of all kind of charts in ngx-echarts?

Ive tried (html): &lt;div echarts [options]=&quot;chartOption&quot; [theme]=&quot;colorScheme&quot; class=&quot;demo-chart&quot;&gt;&lt;/div&gt;

(ts):

colorScheme = {
    domain: [
      &#39;#2FDF75&#39;,
      &#39;#246EB9&#39;,
      &#39;#BCD3F2&#39;,
      &#39;#323031&#39;,
      &#39;#FBFFF1&#39;,
      &#39;#CCFF90&#39;,
      &#39;#FFFF8D&#39;,
      &#39;#FF9E80&#39;
    ]
  };

The colors do not change. I am afraid that the format of my custom theme is not the right one. I couldnt find any documentation on how to change the colors of the charts in an easy way.

答案1

得分: 1

你可以在选项中使用 color 属性

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

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent {

  chartOption: any;

  constructor() {
    this.chartOption = {
      color: ['#2FDF75', '#246EB9', '#BCD3F2', '#323031', '#FBFFF1', '#CCFF90', '#FFFF8D', '#FF9E80'],
      // 其他图表选项...
    };
  }
}

HTML

<div echarts [options]="chartOption" class="demo-chart"></div>

示例链接 点击..

希望对你有所帮助..

英文:

you can use the color property in the option

import { Component } from &#39;@angular/core&#39;;

@Component({
  selector: &#39;app-your-component&#39;,
  templateUrl: &#39;./your-component.component.html&#39;,
  styleUrls: [&#39;./your-component.component.css&#39;]
})
export class YourComponent {

  chartOption: any;

  constructor() {
    this.chartOption = {
      color: [&#39;#2FDF75&#39;, &#39;#246EB9&#39;, &#39;#BCD3F2&#39;, &#39;#323031&#39;, &#39;#FBFFF1&#39;, &#39;#CCFF90&#39;, &#39;#FFFF8D&#39;, &#39;#FF9E80&#39;],
      // your other chart options...
    };
  }
}

HTML

&lt;div echarts [options]=&quot;chartOption&quot; class=&quot;demo-chart&quot;&gt;&lt;/div&gt;

example link click..

hope it helpful..

huangapple
  • 本文由 发表于 2023年6月5日 20:41:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406523.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定