Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery MVC5上未使用Chart.Js在X轴上显示日期_Jquery_Asp.net Mvc_Chart.js - Fatal编程技术网

Jquery MVC5上未使用Chart.Js在X轴上显示日期

Jquery MVC5上未使用Chart.Js在X轴上显示日期,jquery,asp.net-mvc,chart.js,Jquery,Asp.net Mvc,Chart.js,使用chart.js的我的折线图是在X轴上显示日期的NOT。可以在调试模式下看到日期(来自Json控制器)。Y轴很好。 请参阅我的图表: 它应该显示如下情况: 1) branch2计数=1,起始日期='2019-10-02' 2) branch2计数=1,起始日期=2019-09-30 我尝试了stackoverflow提供的示例,但没有成功 var dataChart = { label: [], datasets: [

使用chart.js的我的折线图是在X轴上显示日期的NOT。可以在调试模式下看到日期(来自Json控制器)。Y轴很好。 请参阅我的图表:

它应该显示如下情况:

1) branch2计数=1,起始日期='2019-10-02'

2) branch2计数=1,起始日期=2019-09-30

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

var dataChart = {
           label: [],
           datasets: [
               {
                   label: "Branch1",
                   backgroundColor: "rgba(0, 0, 255, 0.31)",
                   borderColor: "rgba(0, 0, 255, 0.66)",
                   pointBorderColor: "rgba(0, 0, 255,0.70)",
                   pointBackgroundColor: "rgba(0, 0, 255,0.70)",
                   pointHoverBackgroundColor: "#fff",
                   pointHoverBorderColor: "rgba(0, 0, 255, 1)",
                   pointBorderWidth: "1",
                   data: []
               },
               {
                   label: "Branch2",
                   backgroundColor: "rgba(255, 128, 128, 0.31)",
                   borderColor: "rgba(255, 128, 128, 0.66)",
                   pointBorderColor: "rgba(255, 128, 128,0.70)",
                   pointBackgroundColor: "rgba(255, 128, 128,0.70)",
                   pointHoverBackgroundColor: "#fff",
                   pointHoverBorderColor: "rgba(255, 128, 128, 1)",
                   pointBorderWidth: "1",
                   data: []
               },
               {
                   label: "Branch3",
                   backgroundColor: "rgba(0, 204, 153, 0.31)",
                   borderColor: "rgba(0, 204, 153, 0.66)",
                   pointBorderColor: "rgba(0, 204, 153,0.70)",
                   pointBackgroundColor: "rgba(0, 204, 153,0.70)",
                   pointHoverBackgroundColor: "#fff",
                   pointHoverBorderColor: "rgba(0, 204, 153, 1)",
                   pointBorderWidth: "1",
                   data: []
               }
           ]
       };

       $.getJSON("TreasuryChart/",
           function(branchData) {
               for (var i = 0; i < branchData.length; i++) {
                   var d = moment(branchData[i].startDate);
                   dataChart.label.push(d);
                   dataChart.datasets[0].data.push(branchData[i].branch1);
                   dataChart.datasets[1].data.push(branchData[i].branch2);
                   dataChart.datasets[2].data.push(branchData[i].branch3);
               }
               var ctx = document.getElementById("TreasuryChart").getContext("2d");
               var myLineChart = new Chart(ctx,
                   {
                       type: "line",
                       data: dataChart,
                       options: {
                           responsive: true,
                           maintainAspectRatio: false,
                           scales: {
                               xAxis: [
                                   {
                                       //display: true,
                                       type: 'time',
                                       time: {
                                           parser: 'MMM D',
                                           unit: 'day',
                                           displayFormats: {
                                               day: 'MMM D'
                                           }
                                       },
                                       ticks: {
                                         source: 'dataChart'
                                       }
                                   }
                               ],
                               yAxes: [
                                   {
                                       ticks: {
                                           beginAtZero: true
                                       }
                                   }
                               ]
                           }
                       }
                   });
           });
var数据图表={
标签:[],
数据集:[
{
标签:“Branch1”,
背景色:“rgba(0,0,255,0.31)”,
边框颜色:“rgba(0,0,255,0.66)”,
pointBorderColor:“rgba(0,025,0.70)”,
pointBackgroundColor:“rgba(0,025,0.70)”,
pointHoverBackgroundColor:#fff“,
pointHoverBorderColor:“rgba(0,0,255,1)”,
点边界宽度:“1”,
数据:[]
},
{
标签:“Branch2”,
背景色:“rgba(255、128、128、0.31)”,
边框颜色:“rgba(255、128、128、0.66)”,
pointBorderColor:“rgba(255128128,0.70)”,
pointBackgroundColor:“rgba(255,128,128,0.70)”,
pointHoverBackgroundColor:#fff“,
pointHoverBorderColor:“rgba(255、128、128、1)”,
点边界宽度:“1”,
数据:[]
},
{
标签:“Branch3”,
背景色:“rgba(0,204,153,0.31)”,
边框颜色:“rgba(0,204,153,0.66)”,
pointBorderColor:“rgba(0,204,153,0.70)”,
pointBackgroundColor:“rgba(0204153,0.70)”,
pointHoverBackgroundColor:#fff“,
pointHoverBorderColor:“rgba(0,204,153,1)”,
点边界宽度:“1”,
数据:[]
}
]
};
$.getJSON(“库藏图表/”,
函数(branchData){
对于(var i=0;i
我希望在格式日月的X轴上显示图表及其日期


感谢您的帮助。

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


}

这是
xAxis
,不是
xAxis
。感谢各位的回复,很抱歉这是我的错。我还拼错了数组标签[],它应该是标签[]。谢谢你的支持,它现在正在工作。哦,你说得对。拼写错误会给你带来困难。自己解决问题,干得好!我希望下次我们能帮助你。:)
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
           }
       }
   ]