简体   繁体   English

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

[英]Datepicker not setting max and min value

I'm setting my minimum value and max value using the sample data in my push function to show it in the date picker.我正在使用推送函数中的示例数据设置最小值和最大值,以将其显示在日期选择器中。 But when I click the date picker, it shows the wrong min and max value, what's wrong with my code?但是当我单击日期选择器时,它显示了错误的最小值和最大值,我的代码有什么问题? I used this to get the min and max value我用它来获得最小值和最大值

"minDate": dataProvider[0].date, "maxDate":dataProvider[dataProvider.length - 1].date, "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>

From the minDate and maxDate documentation :minDatemaxDate文档

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.dateFormat option或相对日期定义的格式的字符串。

Your dates are in the format yyyy-mm-dd , but your dateFormat option is dd-mm-yy .您的日期格式为yyyy-mm-dd ,但您的dateFormat选项为dd-mm-yy

That said, notice the documentation mentions that they can be date objects.也就是说,请注意文档中提到它们可以是日期对象。 You could convert your strings to date objects by wrapping them in new Date(...) .您可以通过将字符串包装在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM