Javascript datepicker日期默认为01-01-1970 HighCharts

时间:2016-08-19 10:00:39

标签: javascript highcharts datepicker

我正在使用datepicker是highcharts,我有2个datepickers。

我的问题是它一直违约到1970年我希望它显示当前月份。 实际显示:01-01-1970。

这是我的代码:

<script type="text/javascript">
    $(function () {


        $.getJSON('test.json?callback=?', function(data) {


            // Create the chart
            window.chart = new Highcharts.StockChart({

                chart: {
                    renderTo: 'container'
                },

                rangeSelector: {
                    selected: 1,
                    inputDateFormat: '%d-%m-%Y',
                    inputDateParser: function (value) {
                        value = value.split('-');
                        return Date.UTC(
                            parseInt(value[2]),
                            parseInt(value[1]) - 1,
                            parseInt(value[0])
                        );
                    },
                },

                title: {
                    text: 'test'
                },

                plotOptions: {
                    series: {
                        cursor: 'pointer',
                        point: {
                            events: {
                                click: function () {



                                }
                            }
                        }
                    }
                },

                series: [{
                    name: 'test',
                    data: data,
                    tooltip: {
                        valueDecimals: 2
                 }}]

            }, function(chart) {

                // apply the date pickers
                setTimeout(function() {
                    $('input.highcharts-range-selector', $('#' + chart.options.chart.renderTo)).datepicker()
                }, 0)
            });
        });


        // Set the datepicker's date format
        $.datepicker.setDefaults({
            dateFormat: 'dd-mm-yy',
            onSelect: function(dateText) {
                this.onchange();
                this.onblur();

            }alert(dateText);
        });


    });

</script>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

请看下面的代码工作正常我也测试了它。

<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" />
<style type="text/css"></style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<script>
$(function() {

    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
        // Create the chart
        window.chart = new Highcharts.StockChart({
            chart: {
                renderTo: 'container'
            },

            rangeSelector: {
                selected: 1,
                inputDateFormat: '%d-%m-%Y'
            },

            title: {
                text: 'AAPL Stock Price'
            },

            series: [{
                name: 'AAPL',
                data: data,
                tooltip: {
                    valueDecimals: 2
                }}]

        }, function(chart) {

            // apply the date pickers
            setTimeout(function() {
                $('input.highcharts-range-selector', $('#' + chart.options.chart.renderTo)).datepicker()
            }, 0)
        });
    });


    // Set the datepicker's date format
    $.datepicker.setDefaults({
        dateFormat: 'dd-mm-yy',
        onSelect: function(dateText) {
            this.onchange();
            this.onblur();
        }
    });

});
</script>

<body>
<div id="container" style="height: 400px; min-width: 600px"></div>

 </body>
</html>