gpt4 book ai didi

javascript - 日期选择器未设置最大值和最小值

转载 作者:行者123 更新时间:2023-11-29 23:00:51 24 4
gpt4 key购买 nike

我正在使用推送函数中的示例数据设置我的最小值和最大值,以在日期选择器中显示它。但是当我点击日期选择器时,它显示了错误的最小值和最大值,我的代码有什么问题吗?我用它来获取最小值和最大值

"minDate": dataProvider[0].date, "maxDate":dataProvider[dataProvider.length - 1].date,

var chartData1 = [];


generateChartData();

function generateChartData() {
chartData1.push(
{
"date": "2012-10-11",
"value": 33
}, {
"date": "2012-12-12",
"value": 50
}, {
"date": "2012-12-13",
"value": 10
}, {
"date": "2012-12-14",
"value": 100
}, {
"date": "2013-12-15",
"value": 30
});


}

var chart = AmCharts.makeChart("chartdiv", {
"type": "stock",
"extendToFullPeriod": false,

"dataSets": [{
"title": "first data set",
"fieldMappings": [{
"fromField": "value",
"toField": "value"
}, {
"fromField": "volume",
"toField": "volume"
}],
"dataProvider": chartData1,
"categoryField": "date"
}],

"panels": [{

"showCategoryAxis": false,
"title": "Value",
"percentHeight": 70,

"stockGraphs": [{
"id": "g1",

"valueField": "value",
"comparable": true,
"compareField": "value",
"balloonText": "[[title]]:<b>[[value]]</b>",
"compareGraphBalloonText": "[[title]]:<b>[[value]]</b>"
}],

"stockLegend": {
"periodValueTextComparing": "[[percents.value.close]]%",
"periodValueTextRegular": "[[value.close]]"
}
},

{
"title": "Volume",
"percentHeight": 30,
"stockGraphs": [{
"valueField": "volume",
"type": "column",
"showBalloon": false,
"fillAlphas": 1
}],

"stockLegend": {
"periodValueTextRegular": "[[value.close]]"
}
}
],

"chartScrollbarSettings": {
"graph": "g1"
},

"chartCursorSettings": {
"valueBalloonsEnabled": true,
fullWidth: true,
cursorAlpha: 0.1
},

"periodSelector": {
"position": "left",
"periods": [{
"period": "MM",
"selected": true,
"count": 1,
"label": "1 month"
}, {
"period": "YYYY",
"count": 1,
"label": "1 year"
}, {
"period": "YTD",
"label": "YTD"
}, {
"period": "MAX",
"label": "MAX"
}]
},

"dataSetSelector": {
"position": "left"
}
});

chart.addListener('rendered', function(event) {
var dataProvider = chart.dataSets[0].dataProvider;
$(".amChartsPeriodSelector .amChartsInputField").datepicker({
"dateFormat": "dd-mm-yy",
"minDate": dataProvider[0].date,
"maxDate": dataProvider[dataProvider.length - 1].date,
"onClose": function() {
$(".amChartsPeriodSelector .amChartsInputField").trigger('blur');
}
});
});
html, body {
width: 100%;
height: 100%;
margin: 0px;
font-family: Verdana;
}

#chartdiv {
width: 100%;
height: 100%;
}
<!-- jQuery stuff -->
<link rel="stylesheet" media="all" href="https://code.jquery.com/ui/1.12.0/themes/ui-lightness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>

<!-- amCharts -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/amstock.js"></script>
<div id="chartdiv"></div>

最佳答案

来自 minDatemaxDate documentation :

minDate

Multiple types supported:

  • A date object containing the minimum date.

  • A string in the format defined by the dateFormat option, or a relative date.

您的日期格式为 yyyy-mm-dd,但您的 dateFormat 选项为 dd-mm-yy

也就是说,请注意文档提到它们可以是日期对象。您可以将字符串转换为日期对象,方法是将它们包装在 new Date(...) 中。

"minDate": new Date(dataProvider[0].date),
"maxDate": new Date(dataProvider[dataProvider.length - 1].date),

var chartData1 = [];


generateChartData();

function generateChartData() {
chartData1.push({
"date": "2012-10-11",
"value": 33
}, {
"date": "2012-12-12",
"value": 50
}, {
"date": "2012-12-13",
"value": 10
}, {
"date": "2012-12-14",
"value": 100
}, {
"date": "2013-12-15",
"value": 30
});


}

var chart = AmCharts.makeChart("chartdiv", {
"type": "stock",
"extendToFullPeriod": false,

"dataSets": [{
"title": "first data set",
"fieldMappings": [{
"fromField": "value",
"toField": "value"
}, {
"fromField": "volume",
"toField": "volume"
}],
"dataProvider": chartData1,
"categoryField": "date"
}],

"panels": [{

"showCategoryAxis": false,
"title": "Value",
"percentHeight": 70,

"stockGraphs": [{
"id": "g1",

"valueField": "value",
"comparable": true,
"compareField": "value",
"balloonText": "[[title]]:<b>[[value]]</b>",
"compareGraphBalloonText": "[[title]]:<b>[[value]]</b>"
}],

"stockLegend": {
"periodValueTextComparing": "[[percents.value.close]]%",
"periodValueTextRegular": "[[value.close]]"
}
},

{
"title": "Volume",
"percentHeight": 30,
"stockGraphs": [{
"valueField": "volume",
"type": "column",
"showBalloon": false,
"fillAlphas": 1
}],

"stockLegend": {
"periodValueTextRegular": "[[value.close]]"
}
}
],

"chartScrollbarSettings": {
"graph": "g1"
},

"chartCursorSettings": {
"valueBalloonsEnabled": true,
fullWidth: true,
cursorAlpha: 0.1
},

"periodSelector": {
"position": "left",
"periods": [{
"period": "MM",
"selected": true,
"count": 1,
"label": "1 month"
}, {
"period": "YYYY",
"count": 1,
"label": "1 year"
}, {
"period": "YTD",
"label": "YTD"
}, {
"period": "MAX",
"label": "MAX"
}]
},

"dataSetSelector": {
"position": "left"
}
});

chart.addListener('rendered', function(event) {
var dataProvider = chart.dataSets[0].dataProvider;
$(".amChartsPeriodSelector .amChartsInputField").datepicker({
"dateFormat": "dd-mm-yy",
"minDate": new Date(dataProvider[0].date),
"maxDate": new Date(dataProvider[dataProvider.length - 1].date),
"onClose": function() {
$(".amChartsPeriodSelector .amChartsInputField").trigger('blur');
}
});
});
html,
body {
width: 100%;
height: 100%;
margin: 0px;
font-family: Verdana;
}

#chartdiv {
width: 100%;
height: 100%;
}
<!-- jQuery stuff -->
<link rel="stylesheet" media="all" href="https://code.jquery.com/ui/1.12.0/themes/ui-lightness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>

<!-- amCharts -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/amstock.js"></script>
<div id="chartdiv"></div>

关于javascript - 日期选择器未设置最大值和最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55737956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com