I have a Highcharts column chart that is fed with 24 different y-values corresponding to x values from 0-23 representing the hour of the day.
Does Highcharts have a built in format for hours 0-23 such that I can have the X-axis show time labels like this:
12am, 1am ...... 12pm, 1pm.....11pm ??
I tried this but Highcharts ignored the x-values:
series: [{
name: 'Time of Day',
data: [['12am', 6],['1am', 1],['3am', 1],['5am', 1],['7am', 2],['8am', 19],['9am', 54],['10am', 80],['11am', 73],['Noon', 92],['1pm', 105],['2pm', 87],['3pm', 100],['4pm', 74],['5pm', 59],['6pm', 38],['7pm', 24],['8pm', 7],['9pm', 10],['10pm', 4],['11pm', 8],]
}]
EDIT:
The data may not include a value for every hour, as you can see in this sample data.
You can specify the format of date/time to be displayed using the php strftime format, http://php.net/manual/en/function.strftime.php.
So for example if you want to change the hours(when and if they are displayed) and minutes(when and if they are displayed) to 12 hour format use %I instead of %H.
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
day: '%e of %b',
minute: '%I:%M',
hour: '%I:%M'
}
}
jsfiddle - http://jsfiddle.net/xya6kato/
You can define your x-axis captions and series separately.
xAxis: {
categories: ['12 am', '1 am', '2 am', '3 am', '4 am', '5 am', '6 am', '7 am', '8 am', '9 am', '10 am', '11 am', 'Noon', '1 pm', '2 pm', '3 pm', '4 pm', '5 pm', '6 pm', '7 pm', '8 pm', '9 pm', '10 pm', '11 pm']
}
series: [{
name: 'Time of Day',
data: [6, 1, 3, 1, 1, 3, 2, 19, 30, 54, 80, 73, 92, 105, 87, 100, 59, 38, 24, 7, 10, 4, 8, 10]
}]
Edit--
If you don't have data for all hours, you can define your xAxis as datetime and provide values in the series for specific hours.
xAxis: {
type: 'datetime',
},
series: [{
name: 'Time of Day',
data: [
[Date.UTC(2014, 2, 28, 10), 5 ],
[Date.UTC(2014, 2, 28, 12), 33 ],
[Date.UTC(2014, 2, 28, 13), 20 ],
[Date.UTC(2014, 2, 28, 15), 26 ]
]
}]
Related
Trying to build a column chart with a range of colors for positive values and another range of colors for negative values.
for example, as much as my value is higher then the color is more "green", I want to add that if the number is less than zero, then as much it is small the color will be more "red".
current situation image
this is my code:
Highcharts.chart('container', {
colorAxis: [{
min: 0,
maxColor: '#1FA37B',
minColor: '#B6E4D5',
},{
max: 0,
maxColor: '#F0BACC',
minColor: '#D1315D',
}],
xAxis: [{
categories: [
"Oct 2021",
"Nov 2021",
"Dec 2021",
"Sep 2021",
"Aug 2021",
"Jul 2021",
"Jun 2021",
"May 2021",
"Apr 2021",
"Mar 2021",
"Feb 2021",
"Jan 2021"
],
reversed: false,
labels: {
step: 1
}
}],
"series": [
{
"data": [[8.00],[18.00],[-8.00],[28.00],[38.00],[-18.00],[ 48.00],[58.00],[-28.00],[68.00],[78.00],[88.00]
],
"type": "column",
"showInLegend": false
}
],
"numberSuffix": "%",
"categoriesFont": "Arial",
"categoriesFontSize": "12px",
"yAxisFontSize": "14px",
"colorByPoint": false,
"appendWidth": 10,
"chartData": [{"date": "2021-10-01"},{"date": "2021-11-01"},{"date": "2021-12-01"},{"date": "2021-09-01"},{"date": "2021-08-01"},{"date": "2021-07-01"},{"date": "2021-06-01"},{"date": "2021-05-01"},{"date": "2021-04-01"},{"date": "2021-03-01"},{"date": "2021-02-01"},{"date": "2021-01-01"}]
});
and jsfiddle: https://jsfiddle.net/8569t3dr/1/
Notice that the colorAxis is defined per series, so if you want to have multiple colorAxis (one for positive values, one for negative) you need to split your series into two independent objects.
Demo: https://jsfiddle.net/BlackLabel/y4x36wmu/
API: https://api.highcharts.com/highcharts/series.line.colorAxis
I have created heat-mp using High-charts.But tick marks which are generated are placed in the middle of the row instead of top of the row on Y-axis, please have a look at the below image
Y-axis configuration
xAxis: {
tickmarkPlacement: 'on',
"tickWidth":1,
"tickPositions":[0,2,4,6,8,10,12,14,16,18,20,22,24],
categories: ['12 am', '1 am', '2 am', '3 am', '4 am', '5 am', '6 am', '7 am', '8 am', '9 am', '10 am', '11 am', 'Noon', '1 pm', '2 pm', '3 pm', '4 pm', '5 pm', '6 pm', '7 pm', '8 pm', '9 pm', '10 pm', '11 pm'],
"min":0,"startOnTick":false,"maxPadding":0,"endOnTick":false,"minPadding":0,
},
Please let me know how can I fix this.
You can use tickmarkPlacement: 'between' to achieve the desired tick positions. To position the label you can use labels.y property:
labels: {
y: -25
}
Live working example: http://jsfiddle.net/kkulig/2q50sdbc/
API references:
http://api.highcharts.com/highcharts/yAxis.labels.y
http://api.highcharts.com/highcharts/yAxis.tickmarkPlacement
I am using a line chart with the 'datetime' xAxis. I have pointStart: 'April 08, 2015 07:00 PM' and tickAmount: 12 for a 12 hour display. The graph shows April 8 on the xAxis, but displays 12am to 12pm instead of the 7am to 7pm.
Here is my configuration:
x_axis_start_time = 'April 08, 2015 07:00 PM -700'.to_datetime
#pv_chart = LazyHighCharts::HighChart.new('graph') do |f|
f.chart({:zoomType =>'x'})
f.options[{
useUTC: false,
scrollbar: { enabled: true }
}]
f.title({ :text=>"PV Module Temperature"})
f.xAxis [
{
type: 'datetime',
pointStart: x_axis_start_time,
pointInterval: 1 * 3600 * 1000,
tickAmount: 12,
tickInterval: 1 * 3600 * 1000,
}
]
f.yAxis [
{
title: {text: "Temperature ( °C )",
margin: 30},
}
]
f.legend(:align => 'center', :verticalAlign => 'bottom', :layout => 'horizontal')
f.series( :name=> 'PV1', :data=> #avg_pv1, color: '#FF6138', \
pointStart: x_axis_start_time, pointInterval: 60 )
f.series( :name=> 'PV2', :data=> #avg_pv2, color: '#00A388', \
pointStart: x_axis_start_time, pointInterval: 60 )
end
Result: http://i.stack.imgur.com/DinTq.png
I read on another SO thread that passing in UNIX epoch or milliseconds works, but when I convert the DateTime object to int and * 1000, the graph does not display. How can I start xAxis labels from a particular hour?
EDIT:
start_time = '2015-04-02 07:00:00 -0700'.to_time
end_time = '2015-04-02 19:00:00 -0700'.to_time
f.xAxis [{
type: 'datetime',
pointStart: start_time,
}]
f.series( :name=> 'PV1', :data=> #avg_pv1, color: '#FF6138', \
pointInterval: min_inter * 60, pointStart: start_time, \
tickInterval: 1 * 3600, tickAmount: 12, \
min: start_time, max: end_time)
This configuration works the way I want the points to display, but the xAxis is not using pointStart: start_time. It uses the date though.
I am trying to integrate JSON specific data into a heatmap offered by highmaps/highcharts.
The example on
Link to HeatMap Demo
shows how to use CSV approach to load the data. But I was not able to get it running with a JSON array. Can anyone provide an equivalent to the CSV from the example to get the same heatmap chart, or show me the way to another example based on JSON?
Thx in advance.
Cheers Peter
You need to convert that to the col/row point instead of date string. You are going to have 2 category axis: x and y. Then the index of x/y axis becomes the [x, y, value]. So, if your data starts on "2013-04-01" then it is your first index such that [ ["2013-04-01",0,-0.7], ["2013-04-02",0,-3.4], ["2013-04-03",0,-1.1] ] becomes:
[ [0,0,-0.7], [1,0,-3.4], [2,0,-1.1] ]
Note that this is just one row's worth of data. What is your y component?
EDIT:
If your yAxis component will be the hour of the day then you would set up your axii like so:
xAxis: {
categories: ['2013-04-01', '2013-04-02', '2013-04-03'],
labels: {
rotation: 90
}
},
yAxis: {
title: {
text: null
},
labels: {
enabled: false
},
categories: ['Midnight', '1 am', '2 am', '3 am', '4 am', '5 am', '6 am', '7 am', '8 am', '9 am', '10 am', '11 am', 'Noon', '1 pm', '2 pm', '3 pm', '4 pm', '5 pm', '6 pm', '7 pm', '8 pm', '9 pm', '10 pm', '11 pm'],
min: 0,
max: 23,
reversed: true
},
Then you series would look something like:
series: [{
borderWidth: 0,
nullColor: '#EFEFEF',
data: [ [0,0,-0.7], [1,0,-3.4], [2,0,-1.1] ]
}]
Live demo.
There are other items I added there that I will let you figure out (why do I set reversed: true, what is the colorAxis, etc). The important thing to note is that the series.data format is different from any other highchart setup.
I'm not sure what's going on, but dates are being displayed on the axis and in tooltips a month out. So the first date in data on this chart is in July but it shows up as in August and so on. Any ideas? I've put the code in a JSFiddle (http://jsfiddle.net/Z2VGL/1/) and also below:
$(function () {
$('#container').highcharts({
chart: {
type: 'spline'
},
title: {
text: ''
},
plotOptions: {
series: {
lineWidth: 5,
marker: {
fillColor: '#FFFFFF',
lineWidth: 2,
radius: 6,
lineColor: null // inherit from series
}
}
},
subtitle: {
text: ''
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e %b',
year: '%b'
}
},
yAxis: {
title: {
text: 'Ability Score (out of 100)',
style: {
color: '#323A45',
fontWeight: 'bold'
}
},
min: 0
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' + Highcharts.dateFormat('%e %b', this.x) + ': ' + this.y;
}
},
series: [{
name: 'Overall Ability',
// Define the data points. All series have a dummy year
// of 1970/71 in order to be compared on the same x axis. Note
// that in JavaScript, months start at 0 for January, 1 for February etc.
data: [
[Date.UTC(2013, 07, 12), 50],
[Date.UTC(2013, 08, 13), 57.9474605576],
[Date.UTC(2013, 08, 14), 58.5667571154],
[Date.UTC(2013, 08, 15), 69.0590308869], ]
}, {
name: 'Target',
data: [
[Date.UTC(2013, 07, 12), 80],
[Date.UTC(2013, 08, 13), 80],
[Date.UTC(2013, 08, 14), 80],
[Date.UTC(2013, 08, 15), 80],
/*
[Date.UTC(2013, 0, 1), 80.0],
[Date.UTC(2013, 1, 1), 80.0],
[Date.UTC(2013, 2, 1), 80.0],
[Date.UTC(2013, 3, 1), 80.0],
[Date.UTC(2013, 4, 1), 80.0],
[Date.UTC(2013, 5, 1), 80.0],
[Date.UTC(2013, 6, 1), 80.0],
[Date.UTC(2013, 7, 1), 80.0]
*/
],
dashStyle: 'longdash',
marker: {
enabled: false
}
}]
});
});
Thanks in advance.
As you can see from this doc: Mozilla JS Reference Date UTC
month
An integer between 0 and 11 representing the month.