在MVC 5上使用Chart.Js在X轴上不显示日期

时间:2019-10-02 09:42:59

标签: jquery asp.net-mvc chart.js

使用Chart.js的我的折线图不会在X轴上显示日期。日期可以在调试模式下查看(来自Json Controller)。 Y轴很好。 参见我的图表:https://gyazo.com/96c992818ce575ac30c59622ed542acf

它应该显示以下情况:

1)branch2 Count = 1,startDate ='2019-10-02'

2)branch2 Count = 1,startDate ='2019-09-30'

我尝试了stackoverflow提供的示例,但没有成功。

S

我希望以日月格式在X轴上显示带有日期的图表。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

简单的拼写错误。是xAxes而不是xAxis。 (而且我将scaleLabel设置为display: true,因为我不知道您使用的是哪种Chart.js版本)

scales: {
   xAxes: [
       {
           //display: true,
           type: 'time',
           time: {
               parser: 'MMM D',
               unit: 'day',
               displayFormats: {
                   day: 'MMM D'
               }
           },
           ticks: {
             source: 'dataChart'
           },
           scaleLabel: {
              display: true
           }
       }
   ],
   yAxes: [
       {
           ticks: {
               beginAtZero: true
           },
           scaleLabel: {
             display: true
           }
       }
   ]

}

相关问题