Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
Javascript ChartJS在IE11中延长了50年_Javascript_Jquery_Charts_Momentjs_Internet Explorer 11 - Fatal编程技术网

Javascript ChartJS在IE11中延长了50年

Javascript ChartJS在IE11中延长了50年,javascript,jquery,charts,momentjs,internet-explorer-11,Javascript,Jquery,Charts,Momentjs,Internet Explorer 11,我在Chrome中有下面的ChartJS图,它使用moment.js在X轴上设置日期时间格式 但在EI 11中,它看起来是这样的。我不明白为什么IE中的年份是从1970年到现在,但在chrome中,它可以很好地绘制数据 这是moment.js的格式问题吗 下面是创建图表的代码 if (data !== null) { $('#_LblAnalysisOverviewChartSaving').css('visibility', 'visible');

我在Chrome中有下面的ChartJS图,它使用moment.js在X轴上设置日期时间格式

但在EI 11中,它看起来是这样的。我不明白为什么IE中的年份是从1970年到现在,但在chrome中,它可以很好地绘制数据

这是moment.js的格式问题吗

下面是创建图表的代码

if (data !== null) {
            $('#_LblAnalysisOverviewChartSaving').css('visibility', 'visible');
            var titleLabel = document.getElementById("LblChartTitleAuctionOverview").lastChild.nodeValue;
            var costLabel = document.getElementById("LblChartCost").lastChild.nodeValue;
            var timeLabel = document.getElementById("LblChartTime").lastChild.nodeValue;

            var dataLines = [];
            var dataLabels = [];
            var xvalues = [];
            // fill lines and labes array
            $.each(data, function (entryindex, entry) {
                dataLines.push(entry['PlotData']);
                dataLabels.push({ label: entry['Label'] });
            });

            // fill x axes values array with strings
            $.each(dataLines, function (index, value) {
                $.each(value, function (index1, value2) {
                    xvalues.push(value2[0]);
                });
            });
            // at this point xvalues is a array containing strings
            // in the form of 10/19/2020 15:50:20   -- (mm/dd/y h:m:s)


            function onlyUnique(value, index, self) {
                return self.indexOf(value) === index;
            }
            // get only unique values for the x axes 
            var unique = xvalues.filter(onlyUnique);
            var momentsArray = [];

            //create moments array 
            $.each(unique, function (index, value) {
                momentsArray.push(moment.utc(value, "DD MMM YY HH:mm:ss"));
            });

            var ctxr = $('#OverviewChart');
            var myChart = new Chart(ctxr, {
                type: 'line',
                data: {
                    labels: momentsArray
                },
                options: {
                    responsive: true,
                    responsiveAnimationDuration: 1,
                    maintainAspectRatio: false,
                    aspectRatio: 1,
                    title: {
                        display: true,
                        text: titleLabel
                    },
                    tooltips: {
                        mode: 'index',
                        intersect: true
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero: true,
                                // Include a currency in the ticks
                                callback: function (value, index, values) {
                                    return curr + value;
                                }
                            },
                            scaleLabel: {
                                display: true,
                                labelString: costLabel
                            }
                        }],
                        xAxes: [{
                            type: 'time',
                            scaleLabel: {
                                display: true,
                                labelString: timeLabel
                            }
                        }]
                    }
                }
            });

            var borderColorsArr = ['rgba(196, 217, 45, 1)', 'rgba(75, 178, 197, 1)'];
            for (let i = 0; i < dataLines.length; i++) {
                var temp = dataLines[i].sort();
                tempArray = []
                for (var x = 0; x < temp.length; x++) {
                    var oneArray = temp[x];
                    for (var ix = 1; ix < oneArray.length; ix++) {
                        var object = {
                            x: oneArray[0],
                            y: oneArray[1],
                        }
                        tempArray.push(object)
                    }
                }
                myChart.data.datasets.push({
                    label: dataLabels[i].label,
                    data: tempArray,
                    borderColor: borderColorsArr[i]
                })
                myChart.update()
            }
        }
if(数据!==null){
$('#"lblanalysovervicewchartsaving').css('visibility','visible');
var titleLabel=document.getElementById(“lblchartTitleActionOverview”).lastChild.nodeValue;
var costLabel=document.getElementById(“LblChartCost”).lastChild.nodeValue;
var timeLabel=document.getElementById(“LblChartTime”).lastChild.nodeValue;
var数据线=[];
var-dataLabels=[];
var xvalues=[];
//填充线和标签数组
$.each(数据、函数(entryindex、条目){
数据线。推送(条目['PlotData']);
push({label:entry['label']});
});
//用字符串填充x轴值数组
$.each(数据行、函数(索引、值){
$.each(值,函数(index1,value2){
xvalues.push(value2[0]);
});
});
//此时,xvalues是一个包含字符串的数组
//形式为2020年10月19日15:50:20——(年月日h:m:s)
函数onlyUnique(值、索引、自身){
返回self.indexOf(value)==索引;
}
//仅获取x轴的唯一值
var unique=xvalues.filter(仅限yunique);
var momentsArray=[];
//创建矩数组
$.each(唯一、函数(索引、值){
momentsArray.push(time.utc(值,“DD-MMM-YY-HH:mm:ss”);
});
var ctxr=$(“#概览图”);
var myChart=新图表(ctxr{
键入:“行”,
数据:{
标签:momentsArray
},
选项:{
回答:是的,
响应动画持续时间:1,
MaintaintAspectRatio:false,
方面:1,
标题:{
显示:对,
文本:标题标签
},
工具提示:{
模式:“索引”,
交集:对
},
比例:{
雅克斯:[{
滴答声:{
贝吉纳泽罗:是的,
//在刻度中包括一种货币
回调:函数(值、索引、值){
返回curr+值;
}
},
scaleLabel:{
显示:对,
标签字符串:costLabel
}
}],
xAxes:[{
键入:“时间”,
scaleLabel:{
显示:对,
标签串:时间标签
}
}]
}
}
});
var borderColorsArr=['rgba(19621745,1)''rgba(75178197,1)';
for(设i=0;i
在所有原始注释之后,我重新定义了x轴值的填充方式。
但我还是得到了完全相同的结果。我希望从我对代码的评论中可以更清楚地看到x轴值是如何生成和格式化的。

您应该使用相应的格式来显式显示。例如,使用日期格式
10/19/2020 15:50:20
,则应为:

momentsArray.push(moment(value, "MM/DD/YYYY hh:mm:ss"));
此外,它也可能与Chart.js版本有关

我用Chart.js 2.8.0right date格式制作了一个示例,它在IE 11和Chrome上运行良好,您可以参考它:

var xvalues=[“10/19/2020 15:50:20”,“10/19/2020 15:50:21”,“10/19/2020 15:50:22”];
函数onlyUnique(值、索引、自身){
返回self.indexOf(value)==索引;
}
var unique=xvalues.filter(仅限yunique);
var momentsArray=[];
$.each(唯一、函数(索引、值){
momentsArray.push(力矩(值,“MM/DD/YYYY hh:MM:ss”);
});
var ctxr=$(“#概览图”);
var myChart=新图表(ctxr{
键入:“行”,
数据:{
标签:momentsArray
},
选项:{
比例:{
xAxes:[{
键入:“时间”,
scaleLabel:{
显示:对,
标签串:“时间”
}
}]
}
}
});

从您发布的内容来看还不清楚,但问题很可能源于相关日期的格式。不同的浏览器允许不同的日期格式,标准ISO格式除外。如果你的日期以字符串开头,你应该在