Chartjs X轴标签和刻度格式

时间:2017-04-09 09:31:47

标签: javascript charts

我正在使用Chartjs来显示时间序列折线图。

我的设置如下......

   this.chartSetup = {
          type: 'line',
          data: {
            labels: this.times,
            datasets: [{
              fill: true,
              lineTension: 0.1,
              backgroundColor: "rgba(75,192,192,0.4)",
              borderColor: "rgba(75,192,192,1)",
              label: title,
              data: this.vals,
              pointRadius: 0,
            }]
          },
          options: {
            spanGaps: true,
            legend: {
              position: 'bottom',
              labels: {
                boxWidth: 10
              }
            },
            tooltips: {
              enabled: false
            },
            responsive: true,
            maintainAspectRatio: false,
            scales: {
              xAxes: [{
                ticks: {
                  stepSize: 6,
                  unitStepSize: 5
                },
                type: 'time',
                time: {
                  displayFormats: {
                    hour: 'h:mm a',
                    minute: 'h:mm a',
                  }
                }
              }],
            },
          }
        };

   Chart.defaults.global.animation.easing = "easeOutBounce";
   this.chart = new Chart(this.canvas.nativeElement, this.chartSetup);

我的图表如下图所示

enter image description here

数据是X轴的日期(标签),只是Y的数字。 时间数据从早上6点到下午6点(价值12小时)

我在这里有几个与X轴标签格式有关的问题。

  1. 最初的6am标签正在被切断

  2. 如何更改X轴标签旋转(因此可能需要90度才能修复截断的第一个值)

  3. 我的数据转到 6pm ,但它显示了一个额外的X轴值( 7pm )。我可以摆脱这个吗?

  4. 提前感谢您提出的任何建议。

2 个答案:

答案 0 :(得分:1)

对我有用的是设置

autoskip: true
autoSkipPadding: 30
点击配置中的

答案 1 :(得分:0)

1,2 - 设置minRotation = 90
3 - 在x轴上设置最大值

相关问题