Auto setting time axis range in highcharts - highcharts
I have a column chart which showing wrong dates :
Here is the fiddle of my code
data: [1432883717000,1432883717000,1433916917000]
All my timestamps belong to October 5th 2015, however the axis starts from 1970. Is there setting for enabling auto determination of time axis range?Is it possible to set point interval etc for this graph?
Set the min for the yAxis:
$(function () {
var series1 = [1432883717000, 1432883717000, 1433916917000];
var series2 = [null, 1433221380470, null];
var min1 = Math.min.apply(null, series1);
$('#container').highcharts({
chart: {
type: 'column'
},
xAxis: {
categories: [800, 801, 802]
},
yAxis: {
type: 'datetime',
min: min1
},
series: [{
name: 'due by time',
data: series1
}, {
name: 'completed time',
data: series2
}
]
});
});
http://jsfiddle.net/5ft61jkq/43/
Related
how to take only categories for x-axis and remove unwanted scaling in Highstock chart
I want create a bar line graphs with navigator,range selector, y axis from both side and graph sector. I implement it using Highcharts.Chart() but it's x-axis not comes properly. when i create x-axis properly after change categories to ["2017-2-3'] then range selector goes to 1970 (default value) so i convert date to milliseconds. Now in the x-axis have unwanted values. I want to show only x-axis values which shows in category array. currently 1m,3m,6m not worked i think it happen because of this x-axis issue. jsfiddle : http://jsfiddle.net/m05sgk3j/1/ $(document).ready(function() { var categories = [1551420000000,1549000800000,1546322400000,1543644000000,1541052000000, 1538373600000, 1535781600000,1533103200000, 1530424800000, 1527832800000, 1525154400000, 1522562400000, 1519884000000, 1517464800000,1514786400000]; new Highcharts.Chart({ chart: { renderTo: 'container' }, title: { text: 'In March 2019, the average CT_HOURS is 10.55 hours.' }, rangeSelector: { enabled: true, buttons: [{ type: 'millisecond', count: 1, text: '1m' }, { type: 'millisecond', count: 3, text: '3m' }, { type: 'millisecond', count: 6, text: '6m' }, { type: 'all', text: 'All' }], selected: 4, inputDateFormat: '%Y-%m-%d', inputEditDateFormat: '%Y-%m-%d' }, navigator: { enabled: true, xAxis: { tickInterval: 15, labels: { /* formatter: function() { return categories[this.pos] } */ } } }, scrollbar: { enabled: true }, xAxis: { // categories: categories, type: 'datetime', tickInterval : 2, // tickInterval: {_tickInterval}, /* labels: { step:10 }, */ /* maxZoom: 30 * 24 * 3600000, */ dateTimeLabelFormats : { day: '%Y-%m' } // crosshair: true, // minRange: 1 }, yAxis: [{ // Primary yAxis labels: { format: '{value}h', style: { color: Highcharts.getOptions().colors[1] } }, title: { text: 'AVERAGE CT_HOURS', style: { color: Highcharts.getOptions().colors[1] } } }, { // Secondary yAxis title: { text: 'REQUEST COUNT', style: { color: Highcharts.getOptions().colors[0] } }, labels: { format: '{value}', style: { color: Highcharts.getOptions().colors[0] } }, opposite: true }], series: [{ name: 'REQUEST COUNT', type: 'column', yAxis: 1, data: [ [1551420000000, 49.9], [1549000800000, 71.5], [1546322400000, 106.4], [1543644000000, 129.2], [1541052000000, 144.0], [1538373600000, 176.0], [1535781600000, 135.6], [1533103200000, 148.5], [1530424800000, 49.9], [1527832800000, 71.5], [1525154400000, 106.4], [1522562400000, 129.2], [1519884000000, 144.0], [1517464800000, 176.0], [1514786400000, 135.6] ], tooltip: { valueSuffix: '' } }, { name: 'AVERAGE CT_HOURS', type: 'spline', data: [[1551420000000, 56.6], [1549000800000, 46.3], [1546322400000, 32.8], [1543644000000, 43.4], [1541052000000, 40.8], [1538373600000, 43.0], [1535781600000, 43.1], [1533103200000, 44.6], [1530424800000, 45.7], [1527832800000, 27.8], [1525154400000, 39.9], [1522562400000, 29.3], [1519884000000, 27.9], [1517464800000, 27.4], [1514786400000, 17.6]], tooltip: { valueSuffix: 'h' } }] }); });
Just comment the tickInterval for the xAxis //tickInterval : 2, Fiddle
First of all, you have unsorted data. If you want to invert your data, use reversed option. Also, the rangeSelector and the tickInterval are wrong. If you use datetime axis, then the basic unit is one millisecond. However, to show dates only from the categories array, use the tickPositions option and formatter function for labels: xAxis: { reversed: true, minRange: 1, type: 'datetime', tickPositions: categories, labels: { formatter: function() { return Highcharts.dateFormat('%Y-%m', this.value); } } }, Live demo: http://jsfiddle.net/BlackLabel/a6Lphq4k/ API Reference: https://api.highcharts.com/highcharts/xAxis.reversed https://api.highcharts.com/highcharts/xAxis.tickPositions https://api.highcharts.com/highcharts/xAxis.labels.formatter
(1) First always make sure that you are injecting timestamps in your categories, and formatting them in : (1-1) xAxis.labels.formatter function [for x axis labels] (1-2) navigator.xAxis.labels.formatter function [for navigation labels format) (2) Second make sure that you are clearing your (xAxis.categories) if you push data into it. because highcharts don't sort your array. if you just assign new array that's ok. (3) Note : Based on values on your categories array, navigation gets some values like xAxis min and xAxis Max. when you change your data these values remain and that's why your navigation collapses. so when changing data make sure to update. you can use 0 for minimum of navigator and categories.length for maximum value of navigator. you can access updated values also in dataMin and dataMax. Hope this answer help you.
High Charts xAxis first label repeating on all ticks
I am using Highchart to create a chart. I am using xAxis type: 'datetime' my first xAxis label is showing repeatedly. When i add tickInterval all graph ticks overlaps on one and another, So i used pointInterval instead. All graph options are working except first xAxis label which is showing repeatedly. here is my options js: $(function () { $('#container').highcharts({ chart: { type: 'area'}, title: {text: null}, exporting: { enabled: false }, xAxis: { type: 'datetime', pointInterval: 24 * 3600 * 1000, labels: { padding: 0, step: 1, formatter : function() { var dayStr = Highcharts.dateFormat('%a ',this.value); return dayStr; } }, startOnTick: true, endOnTick: false }, yAxis: { min: <?php echo $this_min;?>, max: <?php echo $this_max;?>, title: { text:'mmHg' } }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series: [{showInLegend: false, name:'diastolic', data:[[1464998400, 130], [1465171200, 125], [1465344000, 120], [1465430400, 122]]}, {showInLegend: false, name:'systolic', data:[[1464998400, 90], [1465171200, 85], [1465344000, 80], [1465430400, 82]]}], tooltip: { formatter: function() { var s = []; $.each(this.points, function(i, point) { s.push('<span style="font-weight:bold;">'+point.y +'<span>'); }); return s.join('/')+' mmHg'; }, shared: true }, credits: { enabled: false} }); });
I rewrote your code in jsFiddle. The timestamp [1464998400, 1465171200, 1465344000, 1465430400] that you used in series is pointing to the same date which is Jan 18 1970 and that's why your x-axis label seems repeating. Check out my modified code #line#54 and the label is working fine now.
pointInterval is no longer available in the new version of Highchart. You should use tickInterval instead.
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,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1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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], 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/
Highcharts plot offset on line graph with categories
How can I have a line graph with categories, but plot the lines in between the categories label? Is there a way to offset the plot to the beginning of the tick width? Here is an example: http://jsfiddle.net/jMcfG/1/ I want the line to begin on the origin on the x axis, just like it would if the categories wouldn't be there. $(function () { var chart = new Highcharts.Chart({ chart: { renderTo: 'container' }, xAxis: { categories: ['0', '1', '2', '3', '4'] }, series: [{ data: [0,3,2,5] }] }); });
You can stick you chart to the bottom using threshold property. Like this: $(function () { var chart = new Highcharts.Chart({ chart: { renderTo: 'container', }, plotOptions: { series: { threshold: 0 }, }, xAxis: { categories: ['0', '1', '2', '3', '4'], }, series: [{ data: [0,3,2,5] }] }); }); http://jsfiddle.net/jMcfG/5/ For x-axis this is not possible with use of an API. You will need to do some custom programming. It's a feture that centers graph if categories are present.
I did find an alternative solution which is to add an imaginary point which mirrors the first plot and then set the x axis min to 1 to cut it out, so the graph will cross the origin and will only be visible on the positive side. http://jsfiddle.net/jMcfG/7/ $(function () { var chart = new Highcharts.Chart({ chart: { renderTo: 'container' }, xAxis: { min: 1, categories: ['-13', '0', '1', '2', '3', '4'] }, yAxis: { min: 0, minPadding: 1 }, series: [{ data: [-1,1,3,2,5] }] }); });
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] }] }); });