带有 Highstocks/Highcharts 的 jQuery 日期选择器 [英] jQuery datepicker with Highstocks / Highcharts
本文介绍了带有 Highstocks/Highcharts 的 jQuery 日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 highcharts rangeselector 获得一个有效的 jQuery 日期选择器?
How can I get a working jQuery datepicker with highcharts rangeselector?
这个小提琴是一个有问题的老例子(来自 highcharts 作者).
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('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: '%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();
}
});
});
推荐答案
您可以在选择日期后设置极端,使用您的 onSelect 事件并删除 this.onchange().
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();
}
});
示例:
http://jsfiddle.net/BWEm5/542/
这篇关于带有 Highstocks/Highcharts 的 jQuery 日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文