简体   繁体   English

Highcharts股票图表中的MonthPicker不更改月份

[英]MonthPicker in Highcharts Stockchart not changing month

I am trying to initialize a month picker in my highchjarts stockchart 我正在尝试在highchjarts股票图表中初始化一个月选择器

My data only contain yy-mm x axis, so I am using the jquery extension "MonthPicker" https://github.com/KidSysco/jquery-ui-month-picker 我的数据仅包含yy-mm x轴,因此我正在使用jquery扩展“ MonthPicker” https://github.com/KidSysco/jquery-ui-month-picker

I can get everything working other than when I select the new month/year, the chart does not adjust the selected dates x axis - I have also tried the setExtremes method using the event "OnAfterChooseMonth" with the api .MonthPicker('GetSelectedDate') but with no success 除了选择新的月份/年份之外,我还可以使所有工作正常,图表不会调整所选的日期x轴-我还尝试通过事件“ OnAfterChooseMonth”和api .MonthPicker('GetSelectedDate')使用setExtremes方法但没有成功

Any ideas? 有任何想法吗? Thank you https://jsfiddle.net/ayzwnfrt/2/ 谢谢https://jsfiddle.net/ayzwnfrt/2/

$(document).ready(function() {
// Create the chart
window.chart = new Highcharts.StockChart({
            chart: {
            renderTo: 'container'
        },
            rangeSelector: {
        selected: 2,
        inputDateFormat: '%Y-%m',
                    inputEditDateFormat: '%Y-%m'
    },
    title: {
        text: 'Price'
    },
    series: [{
        name: 'Price',
        data: data,
        type: 'spline',
        tooltip: {
            valueDecimals: 2
        }
    }]
}, function(chart) {

        // apply the date pickers
        setTimeout(function() {
            $('input.highcharts-range-selector', $('#' + chart.options.chart.renderTo)).MonthPicker({
            Button: false,
            MaxMonth: -1,
                            MonthFormat: "yy-mm",
            OnAfterChooseMonth: function (selectedDate) {
                alert(selectedDate);
                this.onchange();
                    this.onblur();
            }
            })
        }, 0)
    })

}); });

You need to call xAxis.setExtremes() function with new values passed. 您需要使用传递的新值来调用xAxis.setExtremes()函数。 The best way to call the mentioned function is OnAfterChooseMonth event of MonthPicker plugin. 调用上述函数的最佳方法是MonthPicker插件的OnAfterChooseMonth事件。 I prepared the complete example which shows how to use that function, so please refer to it. 我准备了完整的示例,其中显示了如何使用该功能,因此请参考该示例。

            OnAfterChooseMonth: function (selectedDate) {
                let fromInput = $('input.highcharts-range-selector:eq(0)')[0],
                date = new Date(Date.parse(selectedDate)).toUTCString(),
                offset = new Date(Date.now()).getTimezoneOffset() * 60000,
                extremes = chart.xAxis[0].getExtremes(),
                value = Date.parse(date);                  

              fromInput === this ? 
                    chart.xAxis[0].setExtremes(value - offset, extremes.max) :
                chart.xAxis[0].setExtremes(extremes.min, value - offset)
                // this.onchange();
                    this.onblur();
            }

Live example: https://jsfiddle.net/tx3c7p94/ 实时示例: https //jsfiddle.net/tx3c7p94/

API Reference: https://api.highcharts.com/class-reference/Highcharts.Axis#setExtremes API参考: https //api.highcharts.com/class-reference/Highcharts.Axis#setExtremes

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

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