I want to display a line on maximum and minimum value in my graph. here is js fiddle example.
我想在图表中显示最大值和最小值的一行。这是js小提琴的例子。
http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/stock/demo/yaxis-plotlines/
In this example the maximum and minimum value are hard coded but in my case i'm getting them using this method
在这个例子中,最大值和最小值是硬编码的,但在我的情况下,我正在使用这种方法
var max = Math.max.apply(Math,arr);
var min = Math.min.apply(Math,arr);
console.log(max+"minimum"+min);
Where arr is the array of y-axis.
其中arr是y轴的数组。
The problem is Suppose i'm displaying graph of last 5 years if i select a date range of last 6 month it still show me the max value of last 5 years not last 6 months because my array is of last 5 years value. if i want to display max value on the basis of i select date in graph how can i acheive this ?
问题是假设我显示过去5年的图表,如果我选择过去6个月的日期范围,它仍然显示过去5年的最大值,而不是过去6个月,因为我的数组是最近5年的值。如果我想根据我在图表中选择日期显示最大值我怎么能实现这个?
1 个解决方案
#1
2
update min and max when chart redraw. the min and max is calculated based on selected range
图表重绘时更新最小值和最大值。最小值和最大值根据所选范围计算
[Fiddle][1]
[1]: http://jsfiddle.net/xq8tezqr/
var start = this.xAxis[0].min,
end = this.xAxis[0].max;
var arr = data.filter(function(e){
return e[0]>=start && e[0]<=end
}).map(function(e){return e[1]});
var max = Math.max.apply(Math,arr);
var min = Math.min.apply(Math,arr);
console.log(max+"minimum"+min);
#1
2
update min and max when chart redraw. the min and max is calculated based on selected range
图表重绘时更新最小值和最大值。最小值和最大值根据所选范围计算
[Fiddle][1]
[1]: http://jsfiddle.net/xq8tezqr/
var start = this.xAxis[0].min,
end = this.xAxis[0].max;
var arr = data.filter(function(e){
return e[0]>=start && e[0]<=end
}).map(function(e){return e[1]});
var max = Math.max.apply(Math,arr);
var min = Math.min.apply(Math,arr);
console.log(max+"minimum"+min);