Angularng2-charts混合图表x轴问题
创始人
2024-10-28 16:30:18
0

在使用ng2-charts库创建混合图表时,可能会遇到x轴标签显示不完整的问题。一种解决方法是使用自定义x轴刻度标签,并将其传递给混合图表组件。

例如,可以在组件类中定义一个自定义刻度数组,以便在HTML模板文件中引用。

import { Component } from '@angular/core';
import { ChartDataSets, ChartOptions, ChartType } from 'chart.js';
import { Label } from 'ng2-charts';

@Component({
  selector: 'app-mixed-chart',
  template: `
    
` }) export class MixedChartComponent { public barLineData: ChartDataSets[]; public barLineLabels: Label[]; public barLineType: ChartType; public barLineOptions: ChartOptions; constructor() { this.barLineType = 'bar'; this.barLineData = [ { data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A', type: 'line', fill: false }, { data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B', type: 'bar' } ]; this.barLineLabels = ['January', 'February', 'March', 'April', 'May', 'June', 'July']; this.barLineOptions = { responsive: true, scales: { xAxes: [{ ticks: { autoSkip: false } }] } }; } }

在上述例子中,我们使用自定义x轴刻度标签,并将"autoSkip"设置为false,以便所有标签都会显示。

this.barLineLabels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];

this.barLineOptions = {
  responsive: true,
  scales: {
    xAxes: [{
      ticks: {
        autoSkip: false
      }
    }]
  }
};

相关内容

热门资讯

黑科技辅助!wepoke黑科技... 黑科技辅助!wepoke黑科技ai设备,(WPK大厅)本来真的有挂,科技教程(有挂分析)是一款可以让...
黑科技辅助!wepoke辅助插... 黑科技辅助!wepoke辅助插件安装,(WePoKe调控)原本真的有挂,AI教程(竟然有挂);WeP...
黑科技辅助!wepoke有挂真... 黑科技辅助!wepoke有挂真的有挂,(WePoKe辅助工具)确实有挂,安装教程(揭秘有挂);WeP...
黑科技辅助!wepokeai代... 黑科技辅助!wepokeai代打,(微扑克钻石)一直存在有挂,微扑克教程(有挂细节);大家肯定在之前...
黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai,(Wepoke必胜)往昔真的是有挂,AA德州教程(有挂讲解);黑科...
黑科技辅助!wepoke有挂真... 黑科技辅助!wepoke有挂真的有挂,(WePoKe辅助器ios)本来有挂,切实教程(竟然有挂);A...
黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai辅助工具,(AAPoKer辅助)一向存在有挂,安装教程(有挂分享);...
黑科技辅助!wepoke有挂真... 黑科技辅助!wepoke有挂真的有挂,(智星德州辅助)都是真的是有挂,新2025教程(有挂功能);智...
黑科技辅助!wepoke智能a... 黑科技辅助!wepoke智能ai辅助工具,(来玩德州app)切实是有挂,靠谱教程(有挂解惑),来玩德...
黑科技辅助!wepokeai代... 黑科技辅助!wepokeai代打,(WePoKe发牌)好像有挂,揭秘教程(有挂秘笈);1、超多福利:...