score:1
Set minRange
to 1 and setExtremes()
to the range you want.
I also add two buttons on the upper right to change the range as you want. If you want to select a specific range, I think you have to create two select
s by yourself and algorithm to change the range.
Edit: Added two select
s to let user set the range.
var min = 10,
max = 14;
var chart = null;
data1 = [1884, 2936, 2039, 1948, 1814, 2071, 2183, 3234, 3426, 2188, 1884, 2936, 2039, 1948, 1814, 2071, 2183, 3234, 3426, 2188]
data2 = [875, 694, 919, 1092, 815, 1137, 1421, 1547, 1737, 1748, 875, 694, 919, 1092, 815, 1137, 1421, 1547, 1737, 1748]
var weeks = ['2017week43', '2017week44', '2017week45', '2017week46', '2017week47', '2017week48', '2017week49', '2017week50', '2017week51', '2017week52', '2018week1', '2018week2', '2018week3', '2018week4', '2018week5', '2018week6', '2018week7', '2018week8', '2018week9', '2018week10']
chart = Highcharts.chart('container', {
chart: {
zoomType: 'xy'
},
title: {
text: 'Importance'
},
xAxis: {
minRange: 1,
categories: weeks
},
yAxis: {
title: {
text: 'Importance'
}
},
legend: {
enabled: false
},
plotOptions: {
line: {
marker: {
radius: 2
},
dataLabels: {
enabled: true
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
},
series: [{
type: 'line',
name: 'employee1',
data: data1
},
{
type: 'line',
name: 'employee2',
data: data2
}
],
exporting: {
buttons: {
moveRight: {
text: '>>',
onclick: function(){
var canShift = max < 19
max = canShift ? max + 1 : max;
min = canShift ? min + 1 : min;
chart.xAxis[0].setExtremes(min, max)
}
},
increasePeriod: {
text: '+',
onclick: function() {
max = max < 19 ? max + 1 : max;
chart.xAxis[0].setExtremes(min, max)
}
},
decreasePeriod: {
text: '-',
onclick: function() {
max = max > min ? max - 1 : max
chart.xAxis[0].setExtremes(min, max)
}
},
moveLeft: {
text: '<<',
onclick: function() {
var canShift = min > 0
min = canShift ? min - 1 : min;
max = canShift ? max -1 : max;
chart.xAxis[0].setExtremes(min, max)
}
}
}
}
});
$.each(weeks, function(index, week){
$('<option>', {
value: index,
text: week
}).appendTo($('select'))
})
$('select').on('change', function(){
min = parseInt($('#start').val());
max = parseInt($('#end').val());
if(min > max){
max = min
$('#start').val(min)
$('#end').val(max)
}
chart.xAxis[0].setExtremes(min, max)
})
$('#start').val(min)
$('#end').val(max).trigger('change')
chart.showResetZoom();
#container {
height: 400px;
}
<script src="https://img.hcharts.cn/jquery/jquery-1.8.3.min.js"></script>
<script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/exporting.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/oldie.js"></script>
<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
<div id="container"></div>
<div id="rangeSelector">
<select id="start"></select>
<select id="end"></select>
</div>
score:0
You can do this by calling setExtremes()
after the chart has been intitialized, like this:
var maxValue = chart.xAxis[0].getExtremes().max
var minValue = maxValue - 4
chart.xAxis[0].setExtremes(minValue, maxValue, true)
chart.showResetZoom();
And setting the minRange
of the xAxis
:
xAxis: {
minRange: 4,
...
}
I also called showResetZoom
, which will let the user see the "reset zoom" button.
var chart = null;
data1 = [1884, 2936, 2039, 1948, 1814, 2071, 2183, 3234, 3426, 2188, 1884, 2936, 2039, 1948, 1814, 2071, 2183, 3234, 3426, 2188]
data2 = [875, 694, 919, 1092, 815, 1137, 1421, 1547, 1737, 1748, 875, 694, 919, 1092, 815, 1137, 1421, 1547, 1737, 1748]
chart = Highcharts.chart('container', {
chart: {
zoomType: 'xy'
},
title: {
text: 'Importance'
},
xAxis: {
categories: ['2017week43', '2017week44', '2017week45', '2017week46', '2017week47', '2017week48', '2017week49', '2017week50', '2017week51', '2017week52', '2018week1', '2018week2', '2018week3', '2018week4', '2018week5', '2018week6', '2018week7', '2018week8', '2018week9', '2018week10'],
minRange: 4
},
yAxis: {
title: {
text: 'Importance'
}
},
legend: {
enabled: false
},
plotOptions: {
line: {
marker: {
radius: 2
},
dataLabels: {
enabled: true
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
},
series: [{
type: 'line',
name: 'employee1',
data: data1
},
{
type: 'line',
name: 'employee2',
data: data2
}
]
});
var maxValue = chart.xAxis[0].getExtremes().max
var minValue = maxValue - 4
chart.xAxis[0].setExtremes(minValue, maxValue, true)
chart.showResetZoom();
<script src="https://img.hcharts.cn/jquery/jquery-1.8.3.min.js"></script>
<script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/exporting.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/oldie.js"></script>
<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
<div id="container" style="min-width:400px;height:400px"></div>
Jsfiddle example: https://jsfiddle.net/ewolden/wyp8Lfx0/1/
Source: stackoverflow.com
Related Query
- How to use highcharts to display data of only five point when the page is initialized?
- how to enable only 1 out of 2 column column graph by default when page loads in highcharts and the 2nd one gets visible when toggled in the legend
- how do you display only the latest poll data in highcharts
- how to display 2 same highcharts without duplicate the code
- Why do I have the issue 'property assigment expected' when I want to display a chart on my web page using highcharts
- How to display only last data point on highcharts?
- How to make the Y Axis values not start from 0 in highcharts? How to display forcefully display the last category data on X axis in HighCharts ?
- how to continue the graph line when missing series of data in middle of highcharts
- When using Highcharts, how do you get the point name from a data point series?
- How to use axios to fetch data from servlet and then crossfilter it and display via highcharts
- How to display only last point on highcharts and that point should travel with chart line?
- Highcharts: How to move the column bar to the left most side when there is only one point in drilldown
- Highcharts Chart Bar - How can I display in the chart, only one column from my HTML table?
- Highcharts - How would I use HTML input boxes to input the data for a Pie Chart?
- How to use the default colors when specifying patterns in a zone in Highcharts
- How to set point in highcharts when x axis and y axis has data as text values?
- How to plot the X axis data point for uneven tick interval at in Highcharts
- How to make Highcharts to use all the colours when replotting? (it is repeating colours unnecessarily)
- how to use the total property in highcharts point
- how to only display the graph with highcharts
- How to display data coming from the controller as collection in a ViewData dynamically Highcharts
- How can I fix the error #17 "The requested series type does not exist" error when trying to display a highcharts graph in Vue.js?
- how can I use rangeselector and navigation in highcharts in the given code
- HIGHCHARTS - Given a series with UNIX stamps and values pairs for the data, how do I show only the date for the first and last point on xAxis?
- How do I stop Highcharts creating a new gridline at the extremities of the chart unless a data point exceeds the min/max gridline?
- How to display the value instead of percentage in a pie chart using jquery Highcharts
- How to use the tooltip formatter and still display chart color (like it does by default)?
- Highcharts => Getting the id of a point when clicking on a line chart
- How to display No Data Available Message in highcharts
- How to get Highcharts X-Axis Categories starting at the left most point
More Query from same tag
- Highcharts: Set programmatically the crosshair on the first xAxis item
- Highchart multiple level drilldown click event get drilldown series data
- Changing highmap values dynamically
- Highcharts hide categories that don't fit
- Draw custom bars in a Highcharts bar chart
- Highcharts animation not smooth on Chrome
- HighCharts - Set Max and Min values in zoom reset
- Compare two data points inside the tooltip in a Highcharts combination chart
- Increase Height Of Chart On Export
- HighStocks Series Data format
- set different colors for each column in highcharts
- Highcharts series format Issue (AngularJs)
- Highcharts - How to display legend symbol inside the tooltip
- How to update current view in Highstock / Highcharts based on new Plotlines?
- Highcharts axis labels cluttered but after a refresh, it'll be OK
- Highcharts backgroundColor for multiple charts is only applied to one chart
- Options is not defined : Highchart error, Javascript
- Predict future values using highcharts/Highstock
- Is there no way to turn off animation in Highcharts for multiple real-time curves?
- Highchart treemap legends do not show specific legend
- Onclick of a org chart another org chart will open as a modal popup
- Highchart area range on a plot column
- HighCharts - How can I turn off the points?
- show Datalabels (total and dataLabel name) on a column chart- ReactJs highcharts
- Highchart long dataLabels and style width
- How to achieve this graph with highcharts
- highchart set fill color
- Wrong flags arrangement after dynamically set the data on function afterSetExtremes
- Blurry legends in highcharts export pdf
- Highcharts tooltip custom CSS turning the caret/arrow white