简体   繁体   English

如何根据值将颜色线更改为渐变色

[英]How to change color lines to gradient color depending on the value

How to change lines color using ngx-chart ?如何使用ngx-chart更改线条颜色? The goal is to have a color that change depending on the yAxis , with a gradient color.目标是使颜色根据yAxis变化,并带有渐变颜色。

It seems that if I change the schemeType from ordinal to linear , it does what I want to, but this remove the legends.似乎如果我将schemeTypeordinal更改为linear ,它会执行我想要的操作,但这会删除图例。

Like this exemple :像这个例子:

渐变线

Related GitHub issue相关的 GitHub 问题

In order to achieve what I wanted I used the schemeType linear then I created a custom legend using ngx-charts-legend .为了实现我想要的,我使用了schemeType linear然后我使用ngx-charts-legend创建了一个自定义ngx-charts-legend

This is not a perfect solution since we cannot set 2 differents gradients.这不是一个完美的解决方案,因为我们不能设置 2 个不同的梯度。


  <div #containerRef class="d-flex" *ngIf="data.length && !loading">
    <ngx-charts-line-chart [view]="[containerRef.offsetWidth, 400]" [curve]="curve" [schemeType]="'linear'"
      [scheme]="colorScheme" [legend]="legend" [showXAxisLabel]="showXAxisLabel" [showYAxisLabel]="showYAxisLabel"
      [xAxis]="xAxis" [yAxis]="yAxis" [xAxisLabel]="xAxisLabel" [yAxisLabel]="yAxisLabel" [timeline]="timeline"
      [results]="data" [activeEntries]="activeEntries" [roundDomains]="true" [yScaleMin]="0" [yScaleMax]="100">
    </ngx-charts-line-chart>
    <div *ngIf="legend" class="chart-legend custom p-1">
      <ngx-charts-legend [data]="chartNames" [title]="'Legend'" [colors]="colors"
        (labelActivate)="legendLabelActivate($event)" (labelDeactivate)="legendLabelDeactivate($event)">
      </ngx-charts-legend>
    </div>
  </div>
  public data: any[] = [];
  public view: any[];
  // options
  public legend: boolean = true;
  public chartNames: string[] = [];
  public showLabels: boolean = true;
  public animations: boolean = true;
  public xAxis: boolean = false;
  public yAxis: boolean = true;
  public yAxisTicks: number[] = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
  public showYAxisLabel: boolean = true;
  public showXAxisLabel: boolean = true;
  // xAxisLabel: string = 'Year';
  public activeEntries: any[];
  public yAxisLabel: string = 'Batt %';
  public timeline: boolean = true;
  public colorScheme = {
    domain: ['#a8385d', '#0000FF']
  };
  public colors: ColorHelper;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM