I am using highstock for stock charts. Currently the xAxis data are in 24 hr format for intraday.
I want to display the intraday data in 12 hrs format for xAxis.
Can you please tell me how to convert 24hrs time to 12 hrs in Highstock charts??
I tried with dateTimeLabelFormats, but no luck.
Thanks in Advance.
For me dateTimeLabelFormats works perfectly fine, see: http://jsfiddle.net/wmFZx/
$('#container').highcharts({
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
hour: '%I %p'
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
pointStart: Date.UTC(2010, 0, 1),
pointInterval: 2 * 3600 * 1000 // two hours
}]
});
For those coming in late like me(2yrs later), try this:
tooltip: {
xDateFormat: "%A, %b %e, %I:%M%p"
},
xAxis: {
dateTimeLabelFormats : {
hour: "%I %p"
}
}
Here's the JSFiddle: http://jsfiddle.net/4tat369x/
If you have multiple series and share the tooltip, you'll want to modify the dataGrouping dateTimeLabelFormats for your type of chart. Here's what it looks like for a line chart:
plotOptions: {
line: {
dataGrouping: {
dateTimeLabelFormats: {
millisecond: ["%A, %b %e, %H:%M:%S.%L%p", "%A, %b %e, %I:%M:%S.%L%p", "-%I:%M:%S.%L%p"],
second: ["%A, %b %e, %I:%M:%S%p", "%A, %b %e, %I:%M:%S%p", "-%I:%M:%S%p"],
minute: ["%A, %b %e, %I:%M%p", "%A, %b %e, %I:%M%p", "-%I:%M%p"],
hour: ["%A, %b %e, %I:%M%p", "%A, %b %e, %I:%M%p", "-%I:%M%p"],
day: ["%A, %b %e, %Y", "%A, %b %e", "-%A, %b %e, %Y"],
week: ["Week from %A, %b %e, %Y", "%A, %b %e", "-%A, %b %e, %Y"],
month: ["%B %Y", "%B", "-%B %Y"],
year: ["%Y", "%Y", "-%Y"]
}
}
}
}
Related
highcharts x axis values showing wrong format.It show's default date and year like 1970-01-18 but my actual date is 23/02/2019, 00:43:08.i have seen many answers but i didn't solve my problem.
JSfiddle link
"data": [{
"x": 1550862788,
"y": 526.4200000000001
}, {
"x": 1550862790,
"y": 1850.3116666666667
}, {
"x": 1550862793,
"y": 3199.786
}]`
You have passed the incorrect time in the x , current x value is 1550862788 if you passed this into to new Date(1550862788) you will get Mon Jan 19 1970 04:17:42 GMT+0530 (India Standard Time)
If you want 23/02/2019, 00:43:08 to be the starting x-axis value you need to pass 1550862788000 for now I have increment 1hr for each x-axis value.
Highcharts.setOptions({
time: {
useUTC: false
}
});
$(function() {
$('#container').highcharts({
series: [{
"name": "avg_sales",
"color": "#3b6982",
"data": [{
"x": 1550862788000,
"y": 526.4200000000001
}, {
"x": 1550866388000,
"y": 1850.3116666666667
}, {
"x": 1550869988000,
"y": 3199.786
}]
}],
tooltip: {
dateTimeLabelFormats: {
hour: '%A, %b %e, %l %p'
},
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%e. %b %I:%M %P',
second: '%e. %b %I:%M %P',
minute: '%e. %b %I:%M %P',
hour: '%e. %b %I:%M %P',
day: '%e. %b %I:%M %P',
week: '%e. %b %I:%M %P',
month: '%e. %b %I:%M %P',
year: '%e. %b %I:%M %P'
},
},
});
});
Updated Jsfiddle : https://jsfiddle.net/karnan796/veykdm7h/6/
To get the milliseconds for the current or specific date please make use of it currentmillis
As screenshots below, how can I set the first datetime from start?
Code Demo Here:
http://jsbin.com/wegunetayu/edit?js,output
Highcharts.setOptions({
global: {
useUTC: false
}
});
$('#container').highcharts({
title: null,
series: chartData,
tooltip: {
dateTimeLabelFormats: {
hour: '%A, %b %e, %l %p'
},
},
xAxis: {
tickLength: 0,
labels: {
align: 'left'
},
dateTimeLabelFormats: {
hour: '%l %p'
},
type: 'datetime'
},
yAxis: {
title: null
}
});
Screenshots:
Add these parameters to your xAxis:
xAxis: {
startOnTick: true,
minPadding: 0.01,
...
I updated your JsBin
This solution work only there is enough space to show all months on the axis
I am trying to create an X axis with datetime type where every unique date is displayed along with time and subsequent date label displays just time instead of repeating the same date again.
For Ex: If the dates are like, 01/Jan/1970 10:00 AM, 01/Jan/1970 10:30 AM, 01/Jan/1970 11:00 AM etc, i would like to display the x-axis lables like:
01/Jan/1970 10:00 AM, 10:30 AM, 11:00 AM
How can i do that?
$(function () {
$('#container').highcharts({
xAxis: {
type: 'datetime',
labels: {
formatter: function() {
return Highcharts.dateFormat('%d/%b/%Y %H:%M %p', this.value);
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0]
}, {
data: [144.0, 176.0, 135.6, 148.5, 216.4, 194.1]
}]
});
});
Sample
You can put if condition with start date in label formatter function :
labels: {
formatter: function () {
if (this.value == Date.UTC(2010, 0, 1))
return Highcharts.dateFormat('%d/%b/%Y %H:%M %p', this.value);
else
return Highcharts.dateFormat('%H:%M %p', this.value);
}
}
Check the updated jsFiddle
I am trying to graph the length of times that each employee spends on the phone in a bargraph using Highcharts. I am not getting any errors, but the graph is not drawing. Any advice moving forward would be greatly appreciated.
<script type="text/javascript">
<!-- create the highcharts object -->
$(function () {
$('#container').highcharts({
chart: {
type: 'column',
backgroundColor: 'transparent'
},
title: {
text: ''
},
xAxis: {
categories: ['May 2013', 'June 2013', 'July 2013', 'August 2013', 'September 2013', 'October 2013', 'November 2013', 'December 2013', 'January 2014', 'February 2014', 'March 2014', 'April 2014', ]
},
yAxis: {
// type: 'datetime', //y-axis will be in milliseconds
dateTimeLabelFormats: { //force all formats to be hour:minute:second
second: '%H:%M:%S',
minute: '%H:%M:%S',
hour: '%H:%M:%S',
day: '%H:%M:%S',
week: '%H:%M:%S',
month: '%H:%M:%S',
year: '%H:%M:%S'
},
title: {
text: 'Time Spent on Phone'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y} calls</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [
{ name: 'Michelle', data: ["02:19:36", "02:37:26", "01:57:27", "02:23:49", "02:10:49", "02:32:33", "02:16:10", "01:25:01", "00:50:49", "0", "0", "0", ] },{ name: 'Kim', data: ["04:53:56", "09:21:07", "10:32:46", "10:30:21", "09:15:12", "09:15:57", "06:19:16", "08:59:23", "06:11:48", "0", "0", "0", ] },{ name: 'Katie', data: ["0", "0", "0", "0", "0", "0", "0", "08:00:14", "03:59:01", "0", "0", "0", ] }, ]
});
});
</script>
</div>
You need to set your yAxis.type: 'datetime' and you need to format your series.data to be a valid time javascript time. Currently you have yAxis set to just be values (default) and your data is actually a string ("02:19:36" for example). This needs to be converted to a javascript time.
Edit - example of Date.UTC().
To convert your first entry for 'Michelle' use:
Date.UTC(0, 0, 0, 2, 19, 36)
Since you dont care about year/month/day but the function requires year and month I just set them to 0. Replace all your string dates such that yourdata` looks like:
data: [Date.UTC(0, 0, 0, 2, 19, 36), Date.UTC(....), etc]
Here is an updated fiddle with just one set of data. Noticed I changed series type to 'line. The 'column' type was acting funny.
Fixed the 'column' type issue but setting arbitrary yAxis min year/month/day and setting the data points to use that same value so that the only difference is the time.
Hy!
I need help with highchart. In xAxis I have datetime formated, that was come from epoch time.
Its displaying the hour:minute:seconds and milliseconds but I don't need millisec.
In codeigniter I have highchart library and I can't find out the solution to hide or remove millisec from xAxis.
Please if somebody have some idea it would be great!
Could you convert the epoch time to string format, like '2012/2/29', then add them into an array.
E.g.
xAxis: {categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}
See highchart demo here for example.
If your chart is zoomable you'll have to set the option dateTimeLabelFormats for your xAxis
xAxis: {
...
dateTimeLabelFormats: {
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
}
}
or you can use the label formatter for the xAxis:
xAxis: {
...
labels: {
formatter: function() {
return <whatever format you wish for this.x value>;
}
}
...
}