Set max & min xAxis value for scrolling - highcharts

I have a highstock chart that displays sensor data using ajax request.
Everytime the extremes change on the xAxis I am loading the relevant data from the server and display it.
On the page I also have two dateTime controls to select start and end date of the period you want to watch the data from.
Now I have the problem that when I set start to 11/28/2012 and end also to 11/28/2012 and I scroll (minimum range is 1 day) the user is able to scroll out of the selected range which I am trying to prohibit.
I couldn't find any examples or solutions that work.
I tried setting the chart.navigator.xAxis.min and max, also tried to set chart.xAxis.min and max but this isn't working...
Take a look yourself here:
http://carbocount.wikidot.com/project:products:visualization

I managed to fix this problem on my own.
In the afterSetExtremes event I checked the extremes using e.dataMin and e.dataMax if the range is between the selected time period. It not I reset the extremes:
// if the user tries to zoom outside of the selected time period
// cancel the event and reset extremes
var extremesReset = false;
if (e.dataMin < plotStart.getTime()) {
e.dataMin = plotStart.getTime();
extremesReset = true;
}
if (e.dataMax > plotEnd.getTime()) {
e.dataMax = plotEnd.getTime();
extremesReset = true;
}
var chart = $('#plot').highcharts();
if (extremesReset)
chart.xAxis[0].setExtremes(e.dataMin, e.dataMax);

Related

Highcharts - Selection Event Modify Options

This is my selection event handler in my code which I am for specific zoom timezones as you can see. What I am trying to achieve is to change the xAxis labels based on the zoom. Currently the following code does not work but I can not seem to find a solution to this problem online. Any thought?
Real question would be how can I alter highchart options through events. From the event parameter in the function I can access information but I can not change it.
I have two aproach, the first with changing inside event chart.redraw() will be called every time when chart is redrawn, for testing I added fired from a button.
redraw: function() {
let chart = this;
console.log(chart);
chart.xAxis[0].userMax = 8;
chart.xAxis[0].userMin = 2;
},
The next way is to update the axis object with a new set of userMax and userMin options.
chart.xAxis[0].update({
userMax: 8,
userMin: 2
}, true);
Live demo:
https://jsfiddle.net/BlackLabel/fcsd9hyo/
API References:
https://api.highcharts.com/highcharts/chart.events.redraw
https://api.highcharts.com/class-reference/Highcharts.Axis#update

How to keep the hover state with Highcharts

Currently it is possible for me to manually trigger hover event of highcharts like below code to show tooltip and highlight the series.
chart.series[0].points[2].onMouseOver()
However the state can be easily changed after moving the mouse.Is there a way for me to keep the state?
If you want to keep your tooltip visible when mouse pointer is out you need to disabled tooltip.hide functionality.
Highcharts.Tooltip.prototype.hide = function() {};
and highligt point again after mouse out:
events: {
mouseOut() {
let series = this;
series.points[2].onMouseOver();
}
}
Demo: https://jsfiddle.net/BlackLabel/xjzc25aL/
For those who are simply trying to make the tooltip visible for a longer time, there is the hideDelay property.
For example, to make it last 5 seconds you can write
chart.tooltip.options.hideDelay = 5000;

Highcharts position dataLabels on hide/show event

Our purpose: We are working on a function that avoids overlapping dataLabels by repositioning. Doing so we are facing problems when updating the dataLabel position by the show event. To illustrate our problem we included a simplified example with a function that repositions the first dataLabel of each visible series by 30px to the top (y-direction). The reposition-function is fired by the show event.
... function adjustLables(chart, visibleIndex) {
console.log('dataLabels');
for (var i = 0; i < visibleIndex.length; i++) {
var index = visibleIndex[i],
dataLabel = chart.series[index].points[0].dataLabel,
adjY = dataLabel.y - 30;
chart.series[index].points[0].dataLabel.attr({
y: adjY
});
console.log(chart.series[index].name, 'dataLabel.y:', dataLabel.y, ', adjY:', adjY, dataLabel);
};
console.log('\n');
}; ...
Our problem:
Although our function adjusts the dataLabel.y property by applying .attr({y: adjY}), the dataLabel object does not behave in the way we expected.
For example: (see fiddle and the following description)
The repositioning works only once for a series that is shown by clicking the legend item for the first time. If one decativates and activates the same series again our adjustment does not work any longer.
(e.g. Activate series2 in our fiddle and you will see that its first dataLabel is moved 30px to the top. However, deactivate / reactivate series2 and the dataLabel is no longer moved 30px to the top but appears at its standard position.)
For debugging this mysterious deactivate/activate behavior we logged some information to the console after .attr() is called: seriesName, dataLabel.y, adjY, dataLabel-object. Surprisingly, although the dataLabel.y and adjY values are the same the dataLabel object itself remains unaffected at its y-property.
Overall we are wondering whether the show event is the proper way to "update" the dataLabel positions. Any experience or suggestions are very welcome.
I think this is caused mainly by animations, disable it for debugging: http://jsfiddle.net/pbNfz/1/ - works better now.
Also, see this very similar question.

Datetime Highchart with selection event, set wrongly the extremes

I am trying to do the same as regular zooming, but I use:
events : { selection : function(event) {
instead of the regular zooming (it is part of something --> Launch Highcharts zooming programmatically (after a selection))
The problem. When I select (via selection, like zooming) an interval (for example something between 00:00 and 01:00) the zoom shows another area. How can I solve this?
http://jsfiddle.net/FSfR2/4/
You've overcomplicated your problem, just pass the min and max you get in the event to the setExtremes function
chart.xAxis[0].setExtremes(event.xAxis[0].min, event.xAxis[0].max);
http://jsfiddle.net/bhlaird/wmyM4/

Blackberry return to the previus position in ListField

In my application I'm using a list.
This list can be updated by a refresh list button which is retriving more data from serever.
When user pressing the refresh button, my application seves the last selected item into a memeber field -
lastPosition = listField.getSelectedIndex();
After updating the list, my application uses -
listField.setSelectedIndex(lastPosition);
for setting the last position.
But nothing happen.
How can i "move" the list's cursor to point on the lastPosition?
Thanks,
Eyal.
listField.setKeyword("");
listField.v = userVector;
listField.updateList();
listField.getResultList();
listField.setSelectedIndex(lastPosition);
listField.setFocus();
Manager manager = listField.getManager();
int rowHeight = listField.getRowHeight();
manager.setVerticalScroll(lastPosition * rowHeight);
listField.invalidate();
It's hard to guess what is wrong without seeing the code, however the first thing that comes to mind is probably you don't set focus on the list right after you restore the position? If you don't, then try it:
listField.setSelectedIndex(lastPosition);
listField.setFocus();

Resources