I have a working, simple highchart chart which plots 'score' against 'time'. There's a demo here: http://jsfiddle.net/akfwsq1e/.
The series data is in the form [time, score]:
"data": [
[1540398983, 3],
[1540398983, 2],
[1540398983, 3],
[1540398983, 2],
[1540398983, 4],
[1540485383, 3]
]
However, I need to append more meta-data as I'd like to extend the chart with filters etc in future. This means that the data from the API is returning named objects:
"data": [
{ 'dateCompleted': 1540398983, 'score': 3, 'category': 'A' },
{ 'dateCompleted': 1540398983, 'score': 2, 'category': 'C' },
{ 'dateCompleted': 1540398983, 'score': 3, 'category': 'A' },
{ 'dateCompleted': 1540398983, 'score': 2, 'category': 'B' },
{ 'dateCompleted': 1540398983, 'score': 4, 'category': 'A' },
{ 'dateCompleted': 1540485383, 'score': 3, 'category': 'C' }
]
For now I'm not too concerned with the filtering, I just need to get the chart to plot the same as it does when using simple object values. When I use named values though the chart silently fails to plot anything.
I can't seem to figure out from the documentation how Highcharts 'knows' which values from a named-object to plot.
Can anyone suggest how to get this working?
Many thanks.
If you won't change the structure of object recieved from server, you could implement your own data parse function, which takes the data with specific structure, and returns the data specially prepared for Highcharts.
Actually it's a bit piece of cake, so I wrote that function:
function mapData(data) {
let arr;
arr = data.map(point => {
return {
x: point.dateCompleted,
y: point.score,
category: point.category
}
})
return arr
}
Live example: http://jsfiddle.net/1jp8v6ns/
Apparently you need to call the values to plot 'x' and 'y' (https://api.highcharts.com/highcharts/series.column.data). So this works:
"data": [
{ 'x': 1540398983, 'y': 3, 'category': 'A' },
{ 'x': 1540398983, 'y': 2, 'category': 'C' },
{ 'x': 1540398983, 'y': 3, 'category': 'A' },
{ 'x': 1540398983, 'y': 2, 'category': 'B' },
{ 'x': 1540398983, 'y': 4, 'category': 'A' },
{ 'x': 1540485383, 'y': 3, 'category': 'C' }
]
Related
Why can't I use strings in data on a highchart doughnut chart? You can use it on Bar charts but not doughnut for some reason?
Example of strings in data for bar chart (no errors):
Fiddle: http://jsfiddle.net/8rsywuc7/
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: ['','','','','']
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
Example of strings in data for doughnut chart (see error):
Fiddle: http://jsfiddle.net/troqjcnz/
"data": [38, 44, 14, 20, 25, 75],
"name": "Male",
},
{
"data": ['','','','','',''],
"name": "Female",
},
{
"data": [38, 44, 14, 20, 25, 75],
"name": "No reply",
}
Notice that there is a big difference between those two series configs. In the first one, the data is an array of empty string, meanwhile in the second data becomes an array of objects where y is set to empty string. If you will do the same in the column, the same error will occur - see: http://jsfiddle.net/8rsywuc7/
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [{
name: 'test',
y: ''
}]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
What can I suggest is:
use null rather than empty strings (I am aware that it is not the same, but the output should be similar), demo: http://jsfiddle.net/BlackLabel/jokbgryz/
change the logic responsible for creating data for something like is done here: http://jsfiddle.net/BlackLabel/9bov21gf/
I am using highcharts graphs, Start point of highcharts is showing in my laptop (maximum resolution: 1920*1080).
But when I am an open same graph in a lower system: maximum resolution (1368*768) That time the first point of x-axis not showing
Note : Given image is not match with data but graph is same.
CODE :
$('#call_cc_graph_data').highcharts({
chart: {
type: 'spline',
zoomType: 'x'
},
title: {
text: 'CPS vs Time'
},
xAxis: {
type: 'datetime',
min : 1533873600000,
max : 1533945599000,
},
series:[{
name: 'CC',
data: [[1533876120000,1],[1533876240000,1],[1533876840000,2],[1533876900000,1],[1533877200000,7],[1533877260000,4],[1533877320000,1]]
}]
});
Expected result of image : It needs to show value 05:00 on starting point of x-axis.
Try with xAxis.startOnTick Doc and maybe xAxis.tickInterval Doc
xAxis: {
type: 'datetime',
min : 1533873600000,
max : 1533945599000,
startOnTick:true,
tickInterval:3600 * 1000 // If 2 hours step is too large
},
Fiddle
You can change default xAxis units option:
xAxis: {
type: 'datetime',
units: [
[
'second', [20, 40]
],
[
'minute', [1, 2, 5, 10, 15, 30]
],
[
'hour', [1, 2, 3, 5, 6, 8, 12]
],
[
'day', [1, 2]
],
[
'week', [1, 2]
],
[
'month', [1, 2, 3, 4, 6]
],
[
'year',
null
]
],
min: 1533876120000,
max: 1533945599000
},
Live demo: http://jsfiddle.net/BlackLabel/pskqo6ad/
API: https://api.highcharts.com/highcharts/xAxis.units
Similar problem: https://github.com/highcharts/highcharts/issues/5437
I use different colors for the bars in a Highcharts bar chart to denote two different groups of data like so (abbreviated):
$(function () {
$('#moduleDistribution').highcharts({
colors: ['red', 'red', '#1aadce', '#1aadce'],
chart: {
type: 'column'
},
xAxis: {
type: 'category'
},
plotOptions: {
series: {
colorByPoint: true
}
},
series: [{
showInLegend: false,
data: [
['node', 291],
['wifi', 289],
['timer', 289],
['net', 285]
]
}]
});
});
Demo: http://jsfiddle.net/7Luob5k8/4/
How can I create a legend (or similar) to explain the meaning of the colors? I'd like to explain to the viewer why some bars are red and some are not.
You can achieve this by using 2 series. Make them visible in the legend. Assign the color you want to it. mention Category names in xAxis and use a [x,y] co-ordinates system to send the data to the chart.
your categories
xAxis: {
categories: ['node', 'wifi', 'timer', 'net', 'gpio', 'file', 'uart', 'i2c', 'mqtt', 'adc', '1wire', 'bit', 'pwm', 'spi', 'u8g', 'cjson', 'ws2812', 'coap']
},
your series will look like this.
series: [{
data: [
[0, 291],
[1, 289],
[2, 289],
[3, 285],
[4, 284],
[5, 283],
[6, 263]
],
color: '#FF0000'
}, {
data: [
[7, 135],
[8, 119],
[9, 100],
[10, 96],
[11, 89],
[12, 80],
[13, 65],
[14, 60],
[15, 57],
[16, 46],
[17, 20]
],
color: '#1aadce'
}]
Here I've updated your fiddle
I'm not quite sure is this a bug or can be configured in Highstock.
I expect the navigator line to looks the same like the series line. With the red marker I drew how it should looks:
The numbers are really small and you can see the implementation here: http://jsfiddle.net/Vangi/mfgwpsLn/1/
chart = new Highcharts.StockChart({
chart: {
renderTo: "container",
},
xAxis: {
type: 'datetime',
},
series: [{
data: [{
'x': 1413981042000,
'y': 1.0307497910755359E-10
}, {
'x': 1414049332000,
'y': 6.8937692958570551E-06
}, {
'x': 1414153012000,
'y': 6.1638593534807384E-12
}, {
'x': 1414156468000,
'y': 6.1457475393489336E-12
}, {
'x': 1414159924000,
'y': 6.1549662935811433E-12
}, {
'x': 1414166836000,
'y': 6.1692543434910263E-12
}, {
'x': 1414170292000,
'y': 6.1634967962742593E-12
}, {
'x': 1414173748000,
'y': 6.1702021530302131E-12
}, {
'x': 1414184401000,
'y': 6.1611544859008216E-12
}]
}]
});
The problem is with y value, which should not cinaon E-12 value, but full number.
data: [{
'x': 1413981042000,
'y': 1
}, {
'x': 1414049332000,
'y': 6
}, {
'x': 1414153012000,
'y': 1
}, {
'x': 1414156468000,
'y': 1
}, {
'x': 1414159924000,
'y': 1
}, {
'x': 1414166836000,
'y': 1
}, {
'x': 1414170292000,
'y': 1
}, {
'x': 1414173748000,
'y': 1
}, {
'x': 1414184401000,
'y': 1
}]
Example: http://jsfiddle.net/uykeoc3j/3/
Is is possible to draw a branched chart like in the picture below using Highcharts?
Here is a quick example of matching up the end points.
series: [{
data: [
[0, 29.9],
[1, 71.5],
[2, 100]
]
},{
data: [
[2, 100],
[3, 150]
]
},{
data: [
[2, 100],
[3, 50]
]
}]
http://jsfiddle.net/YmucT/