2017-04-09 433 views
1

我使用Chartjs来显示时间序列线图。Chartjs X轴标签和刻度格式

我的设置是如下...

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. 初始上午06点标签被切断

  2. 如何更改X轴标签的旋转(90度,以便也许将修复截短第一值)

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

在此先感谢您的任何建议。

回答

0

1,2 - 设置minRotation = 90
3 - 设定你的X最大值轴

1

什么工作对我来说是在蜱配置设置

autoskip: true 
autoSkipPadding: 30