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.
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 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 ]
]
}]
I am looking for a simple example of how to make the time display in one hour increments for a 24 hour period, a la: 8 AM, 9 AM, etc... along the x-axis. The data to be charted will be as follows [time, meter-reading]. All of my attempts to date have not worked.
Please advise if further details need to be provided.
After playing with an official example and the documentation, I found a way to get intervals every two hours but you can get easily intervals every hour.
Here are the options you have to define in your Highcharts creation:
$(function () {
$('#container').highcharts({
chart: { ... },
title: { ... },
subtitle: { ... },
xAxis: {
type: 'datetime',
tickInterval: 3600 * 1000,
...
},
yAxis: { ... },
tooltip: { ... },
legend: { ... },
plotOptions: { ... },
series: [{
...
pointInterval: 3600 * 1000,
pointStart: Date.UTC(2006, 0, 01, 0, 0, 0, 0),
data: [
...
]
}]
});
});
Playing with the tickInterval, pointInterval and pointStart options, you can obtain what you want.
Here is a live example of what I am talking about: http://jsfiddle.net/FxD58/1/
It works very well if you have 24 values in series (like the 24 hours in a day...)