最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery datepicker with HighstocksHighcharts - Stack Overflow

programmeradmin5浏览0评论

How can I get a working jQuery datepicker with highcharts rangeselector?

This fiddle is an old example (from a highcharts author) which has the problem.

/

Changing the end date will reset the start date to the beginning of the data.

$(function() {

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

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

            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: 'yy-mm-dd',
        onSelect: function(dateText) {
            this.onchange();
            this.onblur();
        }
    });

});

How can I get a working jQuery datepicker with highcharts rangeselector?

This fiddle is an old example (from a highcharts author) which has the problem.

http://jsfiddle/BWEm5/

Changing the end date will reset the start date to the beginning of the data.

$(function() {

    $.getJSON('http://www.highcharts./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: '%Y-%m-%d'
            },

            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: 'yy-mm-dd',
        onSelect: function(dateText) {
            this.onchange();
            this.onblur();
        }
    });

});
Share Improve this question asked Oct 4, 2016 at 19:15 user1984528user1984528 4534 silver badges16 bronze badges 1
  • This issue appears to be specific to the latest version (5.0.0) of highcharts/highstock. If I point to a specific older version (4.2.2) then the issue goes away. – user1984528 Commented Oct 4, 2016 at 19:44
Add a ment  | 

2 Answers 2

Reset to default 4

You could set extremes once a date is selected, using your onSelect event and removing this.onchange().

$.datepicker.setDefaults({
        dateFormat: 'yy-mm-dd',
        onSelect: function(dateText) {
            chart.xAxis[0].setExtremes($('input.highcharts-range-selector:eq(0)').datepicker("getDate").getTime(), $('input.highcharts-range-selector:eq(1)').datepicker("getDate").getTime()); 
            //this.onchange();
            this.onblur();
        }
    });

Example:

http://jsfiddle/BWEm5/542/

perhaps this will help

Change range in Highstock dynamically

I be able to update configuration of the displayed chart on the fly by accessing axis objects.

发布评论

评论列表(0)

  1. 暂无评论