Highcharts - Permanent, Draggable Selection Box - highcharts

I am currently experimenting with the Highcharts charting library, and am totally blown away by its capabilities.
Something I am trying to accomplish is to add a permanent, draggable 'selection' box (or mask) to my chart. This selection box will always be a certain fixed width. For example, say my chart has 30 days worth of data, I would like there to be a draggable box with the width of 1 day. Dragging the box up and down the x-axis (over the actual chart data) will fire off other application events using the selected day as a parameter.
I guess I am looking for something very similar to the navigator in Highstock charts - but again the primary difference is keeping a fixed width selection. Any tips or suggestions would be greatly appreciated.

In Highcharts there is no such built-in feature but in Highstock you can also use only scrollbar, see: http://jsfiddle.net/ea7za/ Now you can use or bottom scrollbar or panning (drag on plotting area).
$.getJSON('url.json', function(data) {
var min = data[0][0], // min
max = data[500][0]; // max - e.g. max = min + 24 * 3600 * 1000; as one day
// Create the chart
$('#container').highcharts('StockChart', {
rangeSelector : {
enabled: false
},
navigator: {
enabled: false
},
xAxis: {
min: min,
max: max
},
title : {
text : 'AAPL Stock Price'
},
series : [{
name : 'AAPL',
data : data,
tooltip: {
valueDecimals: 2
}
}]
});
});

Related

Ending Series points don't show up on highchart area type chart for large series data

Here is the Stackblitz Demo of the issue
Preview link (for better visibility): https://highcharts-angular-stock-a1hvg5.stackblitz.io/
Issue is : The last plot that is visible on the right most edge of the chart is of 12/27/2021
This is wrong as the the series data is available till 12/30/2021 and that should be visible on the right most edge instead of 12/27/2021. It however works when we zoom in slider to 1 year period
How can I make the original chart also display data till 12/30/2021 (series maximum)?
This behaviour is caused by the data-gropuing feature. You can disable the feature:
"plotOptions": {
"area": {
...,
dataGrouping: {
enabled: false
}
}
}
or control anchor behaviour:
"plotOptions": {
"area": {
...,
dataGrouping: {
anchor: 'end',
lastAnchor: 'end'
}
}
}
Live demo: https://stackblitz.com/edit/highcharts-angular-stock-mpcl1d
API Reference: https://api.highcharts.com/highstock/series.line.dataGrouping
Docs: https://www.highcharts.com/docs/stock/data-grouping

XAxis tick interval doesn't change automatically in highcharts gantt

I've implemented a Gantt chart that contains some Gantt long bars and their time period is usually more than a couple of months, moreover, the xAxis of the chart shows years and months as you can see below gif. XAxis's tick-interval should change automatically when I change the range of the Gantt period, but it doesn't!
The desired way is that if I change the time range to a month or smaller, xAxis's tick-interval should change to month/week or month/day.
xAxis: {
maxPadding: 0,
max: Date.UTC(2024, 07, 16),
plotLines: [
// some lines
]
}
Ticks on the xAxis are calculated based on the provided data.
When your data range is wide, the ticks also tend to cover a wider period of time. To change default behaviour you might set the tickInterval inside the afterSetExtremes function with the use of the update method.
Inside you might specify some conditions like for example visible range.
events: {
afterSetExtremes: function(e) {
if (this.chart.xAxis[1].max - this.chart.xAxis[1].min < 36e8) {
this.update({
tickInterval: 36e7
})
} else {
this.update({
tickInterval: undefined
})
this.chart.xAxis[1].update({
tickInterval: undefined
})
}
}
}
API:
https://api.highcharts.com/gantt/xAxis.events.afterSetExtremes
https://api.highcharts.com/class-reference/Highcharts.Axis#update
Live demo: https://jsfiddle.net/BlackLabel/9poc65fn/

x-axis tickInterval not working correctly in highstock chart

I'm displaying a number of series in a highstock chart. I chose highstock because I want to show at least 4 hours of data with the option of scrolling if the user adds data points beyond those 4 hours (but I don't want the rangeSelector or navigator enabled, if that pertains to the problem I'm having).
I thought this would be straightforward, but I'm having problems showing 15-minute intervals on the x-axis. When one data point is dynamically added, the graph correctly shows the 15-minute tick intervals, but when more data points are added, the x-axis starts to scale the times incorrectly. If I then refresh the page and display a graph with multiple data points, I get really weird tickIntervals.
Here are my xAxis options:
xAxis: {
type: 'datetime',
min: 1361815200000,
max: 1361829780000,
tickInterval: 15 * 60 * 1000,
minTickInterval: 15 * 60 * 1000, // 15 minute intervals
gridLineWidth: 2,
labels: {
formatter: function () {
var d = new Date(this.value);
return (d.getMinutes() == 0) ? '<b>' + Highcharts.dateFormat('%H:%M', this.value) + '</b>' : d.getMinutes();
}
}
}
You can see the rest here: http://jsfiddle.net/pxCsX/
What am I missing? I've tinkered with minRange, type and other xAxis and series attributes and scoured the highstock docs, but I keep coming up with bupkis.
Setting ordinal to false solves the problem:
xAxis: {
ordinal: false
}

legend overwrites chart

I have a highstock chart with many series. I placed the legend with series names below the chart. The problem is that I cannot know in advance which is the height of the legend, and sometimes it happens to be soo large that it overwrites the graph above.
Is it possible to adapt the size of the graph to the size of the legend in javascript code? Best solution for me would be to keep fixed the size of the graph and enlarge the height of enclosing element.
edit:
a jsfiddle which resembles my situation: http://jsfiddle.net/KfWDD/1/
var chart = new Highcharts.StockChart({
chart: {
renderTo: 'container'
},
legend: {
enabled: true,
},
rangeSelector: {
selected: 1
},
series: [{
name: 'ADBE',
data: ADBE
}, {
name: 'MSFT',
data: MSFT
}]
});
I would like to have the legend below the navigator. I can obtain this by fixing some margins and offsets in the elements, but then the layout breaks if the legend becomes too tall.
You can set maxHeight for the legend, and add fixed margin to make some space for that legend.

Highstocks rounding values, and range not accurate for more then two hours of viewing

I am using highcharts to perform sensor graphing for basic temperatures, or things of that nature. The issue is I have the current default view set at 3 days, but at that view it distorts the y axis data values.
For example, if the majority of the data is 1.5 but there is a value of 10 also, in the three day view the y axis is only showing a range up to 3 or 4. It shows the spike in the actual line graph however when you hover over the point the value is 3 or 4 instead of 10. However, if I shrink the view to 2 hours, the data gets displayed properly and the value then returns to 10 and the y axis accomodates the 10 value.
Also I am having issues with the data being rounded down constantly it seems, since the values should be a steady 1.5 it is constantly being rounded down to 1.
Any help will be appreciated and I will be around the computer all day to answer any questions that someone might have about this issue.
$.getJSON('mkjson.php?device=<?echo $device_name;?>&sensor=<?echo $sensor_name;?>&pin=<?echo $pin;?>&user=<?echo $_SESSION['user'];?>', function(data) {
// Create the chart
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'container',
zoomType: 'x'
},
rangeSelector : {
selected : 1
},
title : {
text : 'Device:<?echo $device_name;?>'
},
subtitle : {
text : 'Sensor:<?echo $sensor_name;?>'
},
xAxis : {
minRange: 600 * 1000 // one hour
},
yAxis : {
title : {
text : '<?echo $unit;?>'
}
},
rangeSelector : {
buttons : [{
type : 'minute',
count : 10,
text : '10m'
}, {
type : 'hour',
count : 1,
text : '1H'
}, {
type : 'day',
count : 1,
text : '1D'
},
{
type : 'day',
count : 3,
text : '3D'
}],
selected : 3,
inputEnabled : false
},
series : [{
name : 'Voltage',
data : data,
tooltip: {
valueDecimals: 2
}
}]
});
});
This is the example of how the data is skewed. The high points to the right are 10, and 13 yet they show up at only 3.
Have a look at dataGrouping as it lets you determine how to group or to have it off completely. It defaults to enabled.
Have you tried to use numberFormat() http://api.highcharts.com/highstock#highcharts.numberFormat()
I've been burned by the auto-rounding; the chart does some sort of value rounding for its internal representation of points.
I only have a workaround - I got around it by storing the data points in a separate array and referencing THAT in the tooltip function.
As of note, if you're using column data and don't turn data grouping off, the chart will round your X values too.

Resources