【问题标题】:Angular using PrimeNG charjs problem with font colorsAngular 使用 PrimeNG charjs 字体颜色问题
【发布时间】:2021-12-27 16:44:51
【问题描述】:

我有这张图表,我想更改标签的颜色

https://i.stack.imgur.com/vsw6x.png

显示为灰色的标签我想把它变成白色,因为它无法读取

我的代码

HTML5:

<div class="box-result">
    <h5 class="title-result">Line Styles</h5>
    <p-chart type="line" [data]="lineStylesData" [options]="lineOptions"></p-chart>
</div>

TS:

lineStylesData: any;
lineOptions: any;

constructor() {}

  ngOnInit(): void {
    this.lineStylesData = {
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
      color: 'red',
      datasets: [
        {
          label: 'First Dataset',
          data: [65, 59, 80, 81, 56, 55, 40],
          fill: false,
          tension: 0.4,
          borderColor: '#42A5F5',
        },
        {
          label: 'Second Dataset',
          data: [28, 48, 40, 19, 86, 27, 90],
          fill: false,
          borderDash: [5, 5],
          tension: 0.4,
          borderColor: '#66BB6A',
        },
        {
          label: 'Third Dataset',
          data: [12, 51, 62, 33, 21, 62, 45],
          fill: true,
          borderColor: '#FFA726',
          tension: 0.4,
          backgroundColor: 'rgba(255,167,38,0.2)',
        },
      ],
    };

    this.lineOptions = {
      legend: {
        fontColor: '#fff',
      },
      scales: {
        xAxes: [
          {
            ticks: {
              fontColor: 'white',
            },
          },
        ],
        yAxes: [
          {
            ticks: {
              fontColor: 'white',
              beginAtZero: true,
            },
          },
        ],
      },
    };

  }

使用 X 和 Y 轴标签的字体颜色解决此问题的任何方法。在此先感谢我尝试了各种堆栈溢出代码,但都没有积极的结果

【问题讨论】:

    标签: angular typescript chart.js primeng


    【解决方案1】:

    您在使用 V3 时使用的是 V2 语法,这两个版本之间存在一些重大的重大更改,所有更改请阅读migration guide 了解所有更改。

    要解决您的问题,您的选项需要如下所示:

    options: {
      scales: {
        x: {
          ticks: {
            color: 'white'
          }
        },
        y: {
          ticks: {
            color: 'white'
          }
        }
      },
      plugins: {
        legend: {
          labels: {
            color: 'white'
          }
        }
      }
    }
    

    【讨论】:

    • 你是最棒的! jajaja 谢谢你
    猜你喜欢
    • 2021-08-08
    • 2014-11-03
    • 2011-08-18
    • 2014-02-19
    • 2020-07-27
    • 2021-06-27
    • 2020-09-24
    • 1970-01-01
    • 2019-03-30
    相关资源
    最近更新 更多