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.
Related
As you can see here: live example
The main problem is when range selector is set to full size, we can see only two lines, without flags at the left side. If range selector is set to smaller range and you drag it to left side, it seems like everything is ok with flags. But if a little part of line will be at chart, everything is going wrong.
I tried to sort series in ascending order, but it didn't make any results.
Still have no clue what's wrong.
Highchart setup:
{
title: {
text: 'Problem with flags'
},
chart: {
zoomType: 'x',
},
yAxis: {
min: 0,
startOnTick: false
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M',
second: '%H:%M',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
showEmpty: true
},
credits: {
enabled: false
},
lang: {
rangeSelectorZoom: ''
},
rangeSelector: {
allButtonsEnabled: false,
inputEnabled: false,
buttonTheme: {
visibility: 'hidden'
},
labelStyle: {
display: 'none'
}
},
plotOptions: {
series: {
turboThreshold: 0
}
},
legend: {
enabled: true
},
series: SERIES ARE AT FIDDLE
}
I found solution, you should set xAxis.ordinal field to false, here is link
I am trying to build a stacked bar with highcharts. I have some issues regarding the date time format on x axis. see here: http://jsfiddle.net/9y2gnnLy/
I want to add to the x axis an interval of 6 months - which begins with the smallest date and ends with the highest. In addition I want to calculate the duration in tooltip. For example the difference between tow dates: current expiring date - retired date = duration. How can I access the retired date on x axis?
$(function () {
$('#container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Stacked bar chart'
},
xAxis: {
categories: ['Microsoft Office 2010', 'Microsoft Office 2013', 'Microsoft Office 365']
},
yAxis: {
type: 'datetime',
labels: {
formatter: function () {
return Highcharts.dateFormat('%b %Y', this.value);
},
}
},
legend: {
enabled: false
},
tooltip: {
formatter: function() {
return '<b>' + this.series.name +'</b><br/>' + '<b>' + this.x +': </b><br/>'+
Highcharts.dateFormat('%b %Y',
new Date(this.y)) + " - "
+ Highcharts.dateFormat('%b %Y',
new Date("Retired Date - How to access the retired date on x axis")) + '<br/><br/><b>Duration: </b>';
}
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'Retired',
color: 'rgba(223, 83, 83, .5)',
data: [Date.parse("1/2/2013"), Date.parse("2/3/2014"), Date.parse("3/4/2015")],
dataLabels: {
enabled: true,
format: '{series.name}'
}
}, {
name: 'Expiring',
data: [Date.parse("1/2/2012"), Date.parse("6/3/2013"), Date.parse("8/4/2014")],
dataLabels: {
enabled: true,
format: "{series.name}"
}
}, {
name: 'Standard',
data: [Date.parse("1/2/2011"), Date.parse("5/3/2012"), Date.parse("4/4/2013")],
dataLabels: {
enabled: true,
format: "{series.name}"
}
}, {
name: 'Planning',
color: 'rgba(119, 152, 191, .5)',
data: [Date.parse("1/2/2010"), Date.parse("9/3/2011"), Date.parse("5/4/2012")],
dataLabels: {
enabled: true,
format: '{series.name}'
}
}]
});
});
Is it possible to group like this?
You can use columnrange type of your series. With this type of series it will be much simpler to make the chart that you want to have.
You can set ranges in your bars, so they will look like they are stacked. You can use grouped categories plugin for adding more category levels
http://www.highcharts.com/plugin-registry/single/11/Grouped-Categories
series: [{
name: '1',
data: [
[Date.UTC(2011, 01, 01), Date.UTC(2011, 02, 01)],
[Date.UTC(2011, 01, 02), Date.UTC(2011, 03, 01)],
[Date.UTC(2011, 01, 01), Date.UTC(2011, 06, 01)]
],
dataLabels: {
enabled: true,
format: "{series.name}"
}
}, {
name: '2',
data: [
[Date.UTC(2011, 02, 01), Date.UTC(2011, 03, 01)],
[Date.UTC(2011, 03, 01), Date.UTC(2011, 10, 01)],
[Date.UTC(2011, 06, 01), Date.UTC(2011, 08, 01)]
],
dataLabels: {
enabled: true,
format: "{series.name}"
}
}]
You can move your dataLabels to center of your bar using align: 'center' paramter:
dataLabels: {
enabled: true,
align: 'center',
formatter: function() {
return this.series.name;
}
}
Here you can see an example how it can work:
http://jsfiddle.net/ttrtb6xt/1/
I tried to make a line chart with highstock but I got a problem with aligning points with ticks on X-axis.
Here are some of my code snippets for the chart.
jQuery('#chart-area').highcharts('StockChart', {
xAxis: {
minRange: 7 * 24 * 3600000,
minTickInterval: 24 * 3600000
},
rangeSelector: {
inputEnabled: true,
selected: 1,
buttons: [
{
type: 'week',
count: 1,
text: '1w'
},
{
type: 'week',
count: 2,
text: '2w'
},
{
type: 'month',
count: 1,
text: '1m'
},
{
type: 'month',
count: 2,
text: '2m'
},
{
type: 'month',
count: 3,
text: '3m'
},
{
type: 'month',
count: 6,
text: '6m'
}
]
},
title: {
text: 'Test Execution Trend'
},
subtitle: {
text: $scope.currentStream
},
series: [
{
name: 'Test Success Percentage',
pointInterval: 24 * 3600 * 1000,
data: $scope.data,
marker: {
enabled: true,
radius: 3
},
shadow: true,
tooltip: {
valueDecimals: 0
}
}
]
}
);
});
}
I don't even know why this could happen. Is there any problems in my codes?
Here is jsfiddle
http://jsfiddle.net/U85D6/
The problem is that your data isn't starting at specific day, but it's about 16:00. Highcharts ticks are placed at 00:00. That example should explain you better: http://jsfiddle.net/U85D6/1/
I have addeed
tooltip: {
xDateFormat: '%A, %b %e, %H:%M'
},
to show full date for points.
I am struggling to solve this issue where I have a Highcharts graph with temperature and humidity.
It has two y-axis, one for temperature and one for humidity.
I have specified that humidity should go to the y-axis id 1, but it does not.
It puts the line in, but it is 'plotted' to the temperature axis values.
See this jsfiddle
$(function () {
$('#container').highcharts({
chart: {
zoomType: 'x',
type: 'spline'
},
title: {
text: 'Temperatures - Vdrivhus'
},
subtitle: {
text: 'last hour'
},
xAxis: {
type: 'datetime',
// dateTimeLabelFormats.setOption("minute", "%H:%M");
dateTimeLabelFormats: { // don't display the dummy year
day: '%e %b',
week: '%e %b %y',
month: '%b %y',
year: '%Y'
}
},
yAxis: [{ // Primary yAxis
labels: {
format: '{value}°C',
style: {
color: '#89A54E'
}
},
title: {
text: 'Temperature',
style: {
color: '#89A54E'
}
}
}, { // Secondary yAxis
title: {
text: 'Humidity',
style: {
color: '#4572A7'
}
},
labels: {
format: '{value} %',
style: {
color: '#4572A7'
}
},
min: 50,
max: 100,
opposite: true
}],
tooltip: {
shared: true
},
series: [{
name: 'Temperature',
// Define the data points.
marker: {
enabled: false
},
yaxis: 0,
tooltip: {
valueSuffix: '°C'
},
data: [
[1387521917000, 5],
[1387522299000, 5.2],
[1387522531000, 5.1],
[1387522809000, 5.1],
[1387523536000, 4.8],
[1387523745000, 4.7],
[1387524008000, 4.7],
[1387524303000, 4.8],
[1387524667000, 4.9],
[1387524904000, 4.9],
[1387525245000, 5]
]
}, {
name: 'Humidity',
marker: {
enabled: false
},
yaxis: 1,
tooltip: {
valueSuffix: '%'
},
data: [
[1387521917000, 74.4],
[1387522299000, 73.6],
[1387522531000, 74],
[1387522809000, 74],
[1387523536000, 82.5],
[1387523745000, 82.4],
[1387524008000, 78.7],
[1387524303000, 75.9],
[1387524667000, 74.6],
[1387524904000, 74.5],
[1387525245000, 74.2]
]
}, ]
});
});
//]]>
Can anyone help me solve this?
It is very simple, yaxis option should be yAxis since JS is case-sensitive.
I think that's it: jsFiddle
We are migrating from a flash based charting library (FusionCharts) to a JavaScript based one (HighCharts).
This is what our current flash charts look like
And this is what I've got so far with HighCharts.
How can I remove the space (marked with big dumb red arrows) between the plot border and the actual chart data?
Here's my code: http://jsfiddle.net/ChrisMBarr/7JAcN/1/
var chart = new Highcharts.Chart({
chart:{
renderTo: 'container',
type: 'areaspline',
plotBorderWidth: 1,
spacingTop:2,
spacingRight:5,
spacingBottom:5,
spacingLeft:2,
borderWidth:1,
borderRadius:0,
borderColor:'#999'
},
credits: {
enabled: false
},
title: {
text: 'Total spam in the last 7 days'
},
legend: {
verticalAlign: 'bottom',
borderWidth: 1,
backgroundColor: '#FFFFFF'
},
xAxis: {
allowDecimals:false,
categories: [
'Thu 2/14',
'Fri 2/15',
'Sat 2/16',
'Sun 2/17',
'Mon 2/18',
'Tue 2/19',
'Wed 2/20'
],
labels: {
staggerLines: 2
},
tickmarkPlacement: 'on',
},
yAxis: {
allowDecimals:false,
alternateGridColor: '#F7F7F7',
title: {
text: 'Number of Emails',
margin:5
}
},
tooltip: {
formatter: function() {
var isSpam = this.series.name === _chartOptions.series[1].name
return ''+this.x +': <strong>'+ this.y +(isSpam ? " Spam" : "") +' Emails</strong>';
}
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
"name": "Total Mail",
"color":"#339999",
"data": [2,3,4,7,8,8,8]
},{
"name": "Spam",
"color":"#003399",
"data": [2,2,4,4,4,6,8]
}]
});
This might help:
xAxis: {
min: 0.5, max: 5.5
...
where max = number of data point minus 1.5
You should use minPadding/maxPadding parameters but it doens't work with categories. So I suggest to remove categoreis, use min value and tickInterval
http://jsfiddle.net/7JAcN/3/
http://api.highcharts.com/highcharts#xAxis.minPadding
xAxis: {
allowDecimals:false,
minPadding:0,
maxPadding:0,
/*categories: [
'Thu 2/14',
'Fri 2/15',
'Sat 2/16',
'Sun 2/17',
'Mon 2/18',
'Tue 2/19',
'Wed 2/20'
],*/
labels: {
staggerLines: 2
},
tickmarkPlacement: 'on',
},
The best way to remove paddings is to add pointPlacement: 'on'
plotOptions: {
areaspline: {
pointPlacement: 'on'
}
}
With option "tickmarkplacement" set to "on", the xAxis "startontick" option might help you:
xAxis: {
startOnTick: false,
tickmarkplacement:"on",
...
see
this jsfiddle, forked from the Highcharts API documentation