Highstock and data units : how to specify data unit? - highcharts
It is 00h03, I am sweating hard and I am done.
I am looking for a good soul to give me a hand with Hightcharts.js's Hightstock options.
I have this simple jsFiddle: https://jsfiddle.net/hsolatges/p4k7ery7/1/
highstockOptions = {
chart: {
zoomType: 'x',
animation: false
},
navigator: {
adaptToUpdatedData: false,
baseSeries: 1
},
scrollbar: {
enabled: false
},
rangeSelector: {
enabled: false
},
yAxis: [{
title: {
text: 'REFERENCE'
}
}],
series: [{
type: 'line',
name: 'Reference',
data: dataset,
downsample: {
threshold: 1000 // 0 disables downsampling
},
turboThreshold: 0
}]
};
My data is an array of arrays of coordinates [x, y]. Full dataset is a 90,000 points from 0 to 60 minutes. I want labels in minutes, ticks in minutes, navigator showing me minutes.
All I would like to do is telling to Highstock that my dataset arguments are in minutes, not dates, not milliseconds. Just minutes!
I have spent hours. And as trivial as it might be, it turns me crazy.
Thanks folks!
Related
Highcharts - degraded tooltip rendering performance
I'm using Highcharts in an Angular 8 application, and while the chart itself renders quite fast, I am encountering some seriously degraded performance rendering tooltips on charts bound to larger data sets. Interestingly the issue seems less related to the number of data points than to the amount of the plot area series fill. We are using Boost (in app.module.ts): Boost(Highcharts); NoData(Highcharts); More(Highcharts); NoData(Highcharts); theme(Highcharts); and this is is the chart's config (series are added dynamically): public baseChartOptions: Highcharts.Options = { chart: { type: 'line', zoomType: 'x', animation: false, height: '55%' }, boost: { enabled: true, useGPUTranslations: true, usePreallocated: true }, legend: { enabled: true, align: 'center', verticalAlign: 'bottom', layout: 'horizontal' }, exporting: { enabled: false }, plotOptions: { series: { lineWidth: 1.5, animation: false, marker: { enabled: false } } }, xAxis: [ { type: 'datetime', dateTimeLabelFormats: { day: '%m/%d' } } as Highcharts.XAxisOptions ], yAxis: [ { minorTickLength: 0, tickLength: 0, title: { text: '' } } ], tooltip: { shared: true, pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y:.0f}</b><br/>', animation: false }, series: [] }; What are best practices for ensuring the best performance in rendering tooltips? I've seen the Highcharts demo showing over 1,000,000 points with good performance, but I don't seem to be able to achieve the same. I've included a short video converted to gif that illustrates the behavior I'm seeing at three different data densities. Thanks for your help! highcharts tooltip performance
The performance should be better when you disable shared tooltip: tooltip: { animation: false, valueDecimals: 2, shared: false } Demo: http://jsfiddle.net/BlackLabel/xhpqedrt/1/
highstock: how to change color in areaspline when series intersect sma
good morning guys, I need your help for a problem that I can not solve. I need to highlight the intersections between a simple data series and the related moving average. The data of the moving average are automatically generated by HighStock and are not calculated by me (otherwise I would have almost solved the problem!). If it is not possible to graphically highlight with different colors every time the series is above or below the moving average I would like to calculate the difference between the two series (in this way I could draw a single line around the zero value with negative red values and values green positive for example). After numerous researches I have not yet solved my problem. I must say that the documentation of HighChart / HighStock is very complete but it is mainly for professionals. Thanks for your help! This is what I need (look at the picture) $('#container').highcharts('StockChart', { title: { text: 'Relative Strenght' }, navigator: { enabled: false }, series: [ { id: 'forza-rel', type: 'spline', name: 'Rel. Str.', data: forza_relativa, }, { name: 'M.A. 5', type: 'sma', linkedTo: 'forza-rel', color:'#FF0000', dashStyle: 'line', marker: { enabled: false }, params: { period: 5 } } ] });
I need to highlight the intersections between a simple data series and the related moving average. It can be done, however, it requires a lot of custom code and it's a bit tricky. I would like to calculate the difference between the two series This can be done easily. SMA is just another series, so you have to loop through SMA series data and make a difference between its data and a basic series data. Than use series.setData() method to update the third series with calculated values (areasplie for example). HTML: <script src="https://code.highcharts.com/stock/highstock.js"></script> <script src="https://code.highcharts.com/stock/modules/exporting.js"></script> <script src="https://code.highcharts.com/stock/indicators/indicators.js"></script> <div id="container" style="height: 400px; min-width: 310px"></div> JS: Highcharts.stockChart('container', { chart: { height: 500, events: { load: function() { var chart = this, series = chart.series, data = [], offset, diff, i; offset = series[0].xData.length - series[1].xData.length; for (i = 0; i < series[1].xData.length; i++) { diff = series[0].yData[i + offset] - series[1].yData[i]; data.push({ x: series[1].xData[i], y: diff }); } chart.series[2].setData(data); } } }, rangeSelector: { selected: 0 }, title: { text: 'AAPL Stock Price' }, legend: { enabled: true }, plotOptions: { series: { showInLegend: true } }, yAxis: [{ height: '60%', top: '0%', id: '0' }, { height: '36%', top: '62%', id: '1' }], series: [{ type: 'spline', id: 'aapl', name: 'AAPL Stock Price', data: data, yAxis: '0' }, { type: 'sma', linkedTo: 'aapl', marker: { enabled: false }, yAxis: '0' }, { type: 'areaspline', yAxis: '1', color: 'green', negativeColor: 'red', data: [] }] }); Demo: https://jsfiddle.net/wchmiel/863n241h/3/
Highcharts Highstock align x-axis gridlines with center of data point
I'm using Highcharts Highstock chart to display daily data. The vertical (x-axis) gridlines do not align with the data point (gridline is to the left of the data point). Does anyone know how to align the gridline with the data point? http://jsfiddle.net/kngz3exf/3/ Highcharts.setOptions({ global: { useUTC: false } }); $(function () { $('#container').highcharts('StockChart', { rangeSelector: { enabled: false }, yAxis: { gridLineWidth: 0 }, xAxis: { gridLineColor: '#000000', gridLineWidth: 1, lineColor: '#000000', tickColor: '#000000', minorGridLineColor: '#000000', minorGridLineWidth: 1, minorTickColor: '#000000', ordinal: true, tickInterval: 86400000, minorTickInterval: 86400000 }, series: [{ data:[ [1417410000000, -0.4818850000000001], [1417496400000, -0.40866199999999997], [1417582800000, 0.20889499999999994], [1417669200000, -0.623542], [1417755600000, -0.060399999999999995], [1418014800000, -0.56108], [1418101200000, 0.30852700000000005], [1418187600000, -0.4492829999999999], [1418274000000, -0.275211], [1418360400000, 0.013063999999999965], [1418619600000, -0.27293900000000004], [1418706000000, 0.49981200000000003], [1418792400000, 0.2362090000000001], [1418878800000, 0.4464490000000003], [1418965200000, 1.2100639999999998], [1419224400000, -0.792635], [1419310800000, 0.14788899999999994], [1419397200000, 0.011684], [1419570000000, 0.08526699999999998], [1419829200000, -0.12494599999999997], [1419915600000, -0.06489100000000003], [1420002000000, 0.279632] ] }] }); });
By changing my date format from ticks to Date.UTC(yyyy, mm, dd), I can get the data point to align with the vertical grid line.
What you need to do is set the useUTC to false. Now your Dec 2nd data show on Dec 2nd axis tick. Note that your data is not going to hit every major tick mark - looks like you are skipping weekends but your axis is not.
DateTime xAxis Label Not Displaying Correct
I have a data set which is loading correctly but the xAxis label is not displaying the same as JSFiddle using the format specified. The JSFiddle share below is the exact code I am using and it displays perfect with the day of the week Sun - Sat. However, when I run it in my application it displays 00:00 and 12:00 repeated for each the 7 days. The only code change in JSFiddle was the data loading from eval(data.d.Histogram) to the actual array. http://jsfiddle.net/ddelella/bZmtT/ $(function () { Highcharts.setOptions({ global: { useUTC: false } }); $('#container').highcharts({ chart: {}, credits: { enabled: false }, title: { text: null }, legend: { enabled: false }, plotOptions: { series: { borderWidth: 0, pointPadding: -.3 } }, xAxis: { tickLength: 2, minPadding: 0, maxPadding: 0, type: 'datetime', dateTimeLabelFormats: { day: '%a' } }, yAxis: { title: { text: null }, allowDecimals: false, min: 0, gridLineWidth: 0 }, series: [{ data: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], type: 'column', name: 'Tractor Quantity', pointStart: Date.parse("12/31/1899 00:00"), pointInterval: (24/288) * 3600 * 1000 }] }); });
It is caused by other date formats, which are default ones, for example, set hour: '%a' and probably will work. See fixed example for one graph, and one with reproduced issue: http://jsfiddle.net/bZmtT/1/
How to always show the plotLine in HighCharts?
I am creating a HighChart with a plotLine in it. The plotLine has a fixed value, while the data can vary between charts. HighChart scales the y-axis automatically based on the maximum value of data, but it doesn't consider the plotLine's value in its calculations. Hence, if the data range encompasses the plotLine value, the plotLine gets shown, but gets cropped out of the viewport if not. Example: $(function () { $(document).ready(function() { var chart = new Highcharts.Chart({ chart: { renderTo: 'container', type: 'column' }, title: { text: 'Dummy Data by Region' }, xAxis: { categories: ['Africa', 'America', 'Asia'] }, yAxis: { plotLines:[{ value:450, color: '#ff0000', width:2, zIndex:4, label:{text:'goal'} }] }, series: [{ name: 'Year 1800', data: [107, 31, 650] }] }); }); }); JSFiddle for above code: http://jsfiddle.net/4R5HH/3/ The goal line (in red) is shown for the default data, but if I change the data to [107, 31, 250], then the plotLine goes out of the graph viewport and hence becomes invisible.
One other option that does not introduce data points: yAxis: { minRange:450, min:0, plotLines:[{ value:450, color: '#ff0000', width:2, zIndex:4, label:{text:'goal'} }] }, This sets the minimum for the yAxis to 0 (this is unlikely to be false in this case) and the minimum Range to 450. See updated fiddle.
You need to add in a point to you chart but disable the marker. I added a new series with scatter plot type and its value equal to the goal value: { name: 'Goal', type: 'scatter', marker: { enabled: false }, data: [450] } See updated jsFiddle: http://jsfiddle.net/wergeld/4R5HH/4/
In some cases, wergeld's solution would be preferable than jank's solution, especially when you are not sure about min and minRange. But wergeld's solution has a minor issue. If you point your mouse over the plot line, it will show a point and tooltip on the point. To avoid this, I have modified his solution and added enableMouseTracking to get rid of the problem. { name: 'Goal', type: 'scatter', marker: { enabled: false }, data: [450], enableMouseTracking: false } See updated jsFiddle: http://jsfiddle.net/4R5HH/570/
You could simply set the max attribute to the max value you will have: yAxis: { max:650 //HERE plotLines... },
Adjust the axis while loading the chart: $(function() { $('#container').highcharts({ chart: { events: { load: function() { var check = $('#container').highcharts(); var min = check.yAxis[0].min; var max = check.yAxis[0].max; var pLine = check.yAxis[0].chart.options.yAxis[0].plotLines[0].value; if (pLine > max) { check.yAxis[0].setExtremes(null, pLine); } if (pLine < min) { check.yAxis[0].setExtremes(pLine, null); } } } }, xAxis: { categories: ['Jan', 'Feb', 'Mar'], }, yAxis: { minPadding: 0.30, plotLines: [{ color: '#FF0000', width: 2, value: 200 }] }, series: [{ data: [70, 60, 95] }] }); });