High Charts xAxis first label repeating on all ticks - highcharts
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.
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.
Plot xrange graph in x axis not in the middle
I'm using highcharts to chart a graph to monitor during the 24 hours when a printer is printing and when a printer is doing nothing. I've accomplished it using the xrange type, and everything is ok. The only issue i'm having is that graph is plotted in the middle of the graph and i'd like it to be drawed in the bottom. What should i check? This is the code i use to create the graph Highcharts.chart('chart', { chart: { type: 'xrange' }, plotOptions: { series: { pointPlacement: 'on', colors: ["#00e205"], } }, xAxis: { type: 'datetime', plotBands: bands, startOnTick: false }, yAxis: { min: 0, startOnTick: false, categories: ['Stampa'], labels: { enabled: false } }, legend : { enabled: false }, tooltip: { formatter: function() { return "Inizio stampa: "+moment(this.x).format('H:mm:ss')+" <br />Fine stampa:"+moment(this.x2).format('H:mm:ss') } }, title: { text: 'Plotter' } });
You can disable startOnTick property and set proper min value for yAxis: yAxis: { min: 0.45, startOnTick: false }, Live demo: http://jsfiddle.net/BlackLabel/o3kxbcum/ API Reference: https://api.highcharts.com/highcharts/yAxis.min
high charts - how do I get a stacked graph to the full width?
I have created a high chart but would like to have a similar voting style to youtube; with positive vs negative. My issue is getting the bar to stay the full width of the graph, I know percentages can fix this but I want whole numbers. http://jsfiddle.net/u6H3b/ $(function () { $('#container').highcharts({ chart: { type: 'bar', marginLeft:0 }, title: { text: 'votes' }, credits: { enabled: false }, xAxis: { categories: ['Apples'], title: { enabled: false } }, exporting: { enabled: false }, yAxis: { min: 0, max:23, title: { enabled: false }, gridLineColor: '#fff', lineColor: '#fff' }, legend: { backgroundColor: '#FFFFFF', reversed: true }, plotOptions: { series: { stacking: 'normal' } }, series: [{ name: 'Yes', data: [20] },{ name: 'No', data: [3] }] }); });
One option is to use 'endOnTick': yAxis: { endOnTick: false, http://jsfiddle.net/f3eFd/ If you want the end tick (23) to show, you could also add: tickInterval:23, http://jsfiddle.net/bLDpg/ If you really want to get fancy, you can define each tick you need. In the following code, it prints ticks at 0, 3 and at 23. tickPositioner: function () { var positions = [0, 3, 23]; return positions; }, http://jsfiddle.net/aSHz3/
I think, all you need to set is endOnTick: false and maxPadding: 0, see: http://jsfiddle.net/u6H3b/1/ The only problem is that last tick is not displayed, if this is issue for you, use tickPositioner as suggested by SteveP.
Highcharts: Area chart: fill in space between 0 and first point
http://jsfiddle.net/gabrielesandoval/efHq7/ Is there a way to fill in the gap between the y-axis and the first point. The first point on my chart should be "25 years" and i would like the area between 0 and 25 to be filled in as well. Even if the tooltip doesn't work for that point, I would just like to visually show that the values between 0 and the first point. I tried adding a point with a x value of zero but that didnt work. The only area charts I have seen where there is no gap between the two axis and the area are examples where the chart is inverted. Is there a proper way to do this? Current Code: $(function () { $('#container').highcharts({ chart: { type: 'areaspline' }, title: { text: 'Monthly Comparison' }, subtitle: { text: '1 vs 2' }, xAxis: { min: 0, categories: [0, '25 years', '30 years', '35 years', '40 years', '45 years'] }, yAxis: { labels: { formatter: function() { return '$' + this.value; } }, min: 0, title: { text: 'Cost' } }, tooltip: { shared: true, valuePrefix: '$' }, credits: { enabled: false }, legend: { enabled: false }, plotOptions: { area: { lineWidth: 1, marker: { enabled: false }, shadow: false, states: { hover: { lineWidth: 1 } } } }, series: [{ type: 'area', name: 'series1', data: [['',60],['25 years',60], ['30 years',60], ['35 years',60], ['40 years',60], ['45 years',60]] }, { type: 'area', name: 'series2', data: [['',90], ['25 years',100], ['30 years',175], ['35 years',300], ['40 years',400], ['45 years',400]] }] }); });
You should set minPadding/maxPadding as 0, but these parameters doesn't work with categories. So you need to use numeric xAxis, instead of categories.
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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,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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/