I am currently successfully plotting wind speed and wind direction using a standard line graph for wind speed and a scatter plot for wind direction.
The current windSpeed and windDirection DOM objects look like this:
windDirection = "[202,229,218,208,230]";
windSpeed = "[9,13.4,12,9.7,6.6]";
In reality both those variables hold hundreds, if not thousands, of data points. Each windDirection data point corresponds to the windSpeed data point at the same location, and there are an equal number of windDirection and windSpeed data points in the data set.
The goal is to plot this data onto a wind rose which has the standard N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW wind rose labels. Very much like shown in the Highcharts Polar Wind Rose demo # highcharts.com but utilizing the existing DOM objects rather than creating HTML tables for the data.
Using two data series like shown below did not produce the desired output.
series: [{
data: windDirection
},{
data: windSpeed
}
]
I proceeded to create a data point pair from my data which follows the Highcharts API Reference for series.data example which produced output like this:
data: [[windDirection1,windSpeed1], [windDirection2,windSpeed2], and so on]
That approach failed as well. You can view it at JSFiddle: http://jsfiddle.net/02v3tduo/19/
Ideally I would like to avoid creating a copy of windDirection and windSpeed in the DOM because both data sets are fairly large already.
I did see this question/answer at SO Highcharts: Wind Rose chart with JSON data but I am not sure that the same answer applies in my case. The proposed answer seems very cumbersome when dealing with large data sets as each of the data series would need to be constructed prior to showing the chart.
I don't know how to proceed at this point. I realize that my data probably needs to be binned into 5-10 degree bins so it doesn't look as "scattered" for the lack of a better term. I can deal with the binning after the wind rose works properly.
In general, it's not clear what you are asking for. However I'll try to answer..
First of all, you are creating string instead of array, any specific reason for that? Simply use:
windDirectionJSON = JSON.parse(windDirection);
windSpeedJSON = JSON.parse(windSpeed);
windDataJSON = [];
for (i = 0; i < windDirectionJSON.length; i++) {
windDataJSON.push([ windDirectionJSON[i], windSpeedJSON[i] ]);
}
Now, define array of categories to be displayed on xAxis:
var categories = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
Then, play around with xAxis:
xAxis: {
min: 0,
max: 360, // max = 360degrees
type: "",
tickInterval: 22.5, // show every 16th label
tickmarkPlacement: 'on',
labels: {
formatter: function () {
return categories[this.value / 22.5] + '°'; // return text for label
}
}
},
And working example: http://jsfiddle.net/02v3tduo/21/
Note: it's good idea to sort your data points by wind-direction, to start from 0. Like this: http://jsfiddle.net/02v3tduo/22/
windDataJSON.sort(function(a,b) { return a[0] - b[0]; });
I have a simple way: You can refer to series data
// Parse the data from an inline table using the Highcharts Data plugin
Highcharts.chart('container', {
chart: {
polar: true,
type: 'column'
},
title: {
text: 'Wind rose for South Shore Met Station, Oregon'
},
subtitle: {
text: 'Source: or.water.usgs.gov'
},
pane: {
size: '85%'
},
legend: {
align: 'right',
verticalAlign: 'top',
y: 100,
layout: 'vertical'
},
xAxis: {
tickmarkPlacement: 'on',
type:'category'
},
yAxis: {
min: 0,
endOnTick: false,
showLastLabel: true,
reversedStacks: false
},
series: [{
"data": [
["ios1", 12],
["ios2", 12],
["ios3", 12],
["ios4", 91],
["ios5", 11],
["ios6", 12],
["ios7", 18],
["ios8",19],
["ios9",12],
["ios10",34],
["ios11",11],
["ios12",71],
["ios13", 66],
["ios14", 21],
],
"type": "column",
"name": "<40G"
}, {
"data": [
["ios1", 12],
["ios2", 33],
["ios3", 12],
["ios4", 10],
["ios5", 11],
["ios6", 13],
["ios7", 9],
["ios8",20],
["ios9",13],
["ios10",74],
["ios11",21],
["ios12",72],
["ios13", 67],
["ios14", 22],
],
"type": "column",
"name": "40-100G,"
}, {
"data": [
["ios1", 12],
["ios2", 34],
["ios3", 23],
["ios4", 11],
["ios5", 31],
["ios6", 14],
["ios7", 10],
["ios8", 21],
["ios9", 14],
["ios10", 21],
["ios11", 21],
["ios12", 73],
["ios13", 68],
["ios14", 23],
],
"type": "column",
"name": "100-500G,"
}, {
"data": [
["ios1", 12],
["ios2", 45],
["ios3", 14],
["ios4", 12],
["ios5", 31],
["ios6", 15],
["ios7", 11],
["ios8", 22],
["ios9", 15],
["ios10", 22],
["ios11", 21],
["ios12", 74],
["ios13", 69],
["ios14", 24],
],
"type": "column",
"name": ">500G"
}],
plotOptions: {
series: {
stacking: 'normal',
shadow: false,
groupPadding: 0,
pointPlacement: 'on'
}
}
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 420px; max-width: 600px; height: 400px; margin: 0 auto"></div>
Related
I want to create like below graph. How can I create like this graph?
The biggest value has to be in the middle of xAxis.
You can use xAxis.categories to set the xAxis labels and next you need to define the x value for each point in the data.
Demo: https://jsfiddle.net/BlackLabel/e7d6c2pm/
Highcharts.chart('container', {
chart: {
type: 'scatter'
},
xAxis: {
categories: ['0m', '150m', '250m', '350m', '550m', '700m', '550m', '350m', '150m', '0m'],
plotLines: [{
value: 5,
color: 'red'
}]
},
series: [{
data: [[0.1, 52], [2, 20], [3, 10], [2.5, 8], [2.8, 13]]
}, {
data: [[6, 52], [8, 20], [9, 10], [8.5, 8], [7, 13]]
}]
});
API: https://api.highcharts.com/highcharts/xAxis.categories
I have a second data series that I would like to add to the tooltip on this Highmaps chart. The variable with the second set of data (data2) is in place, but I haven't added the series yet as each time I do it breaks the code. I would like the tooltip to show the data from the first series and then beneath that, show the data from the second series. So it would read something like:
Value
State name: 4.50
Ranking: 3
I think the second series should be added like this:
{name:'Ranking: ',
data: data2
}
but, like I said, when I add that it breaks the code. Beyond that, I can't figure out how to add that additional data to the tooltip, once I get there.
Here's the javascript code:
// Prepare demo data
// Data is joined to map using value of 'hc-key' property by default.
// See API docs for 'joinBy' for more info on linking data and map.
var data2 = [
['mx-3622', 0],
['mx-bc', 1],
['mx-bs', 2],
['mx-so', 3],
['mx-cl', 4],
['mx-na', 5],
['mx-cm', 6],
['mx-qr', 7],
['mx-mx', 8],
['mx-mo', 9],
['mx-df', 10],
['mx-qt', 11],
['mx-tb', 12],
['mx-cs', 13],
['mx-nl', 14],
['mx-si', 15],
['mx-ch', 16],
['mx-ve', 17],
['mx-za', 18],
['mx-ag', 19],
['mx-ja', 20],
['mx-mi', 21],
['mx-oa', 22],
['mx-pu', 23],
['mx-gr', 24],
['mx-tl', 25],
['mx-tm', 26],
['mx-co', 27],
['mx-yu', 28],
['mx-dg', 29],
['mx-gj', 30],
['mx-sl', 31],
['mx-hg', 32]
];
var data = [
['mx-3622', 0.00],
['mx-bc', 5.59],
['mx-bs', 4.05],
['mx-so', 4.77],
['mx-cl', 6.91],
['mx-na', 8.88],
['mx-cm', 8.01],
['mx-qr', 4.87],
['mx-mx', 5.01],
['mx-mo', 0.089],
['mx-df', 8.12],
['mx-qt', 7.32],
['mx-tb', 3.17],
['mx-cs', 1.15],
['mx-nl', 6.88],
['mx-si', 6.64],
['mx-ch', 2.19],
['mx-ve', 0.66],
['mx-za', 8.03],
['mx-ag', 10],
['mx-ja', 3.35],
['mx-mi', 3.91],
['mx-oa', 0.8],
['mx-pu', 1.53],
['mx-gr', 0.0],
['mx-tl', 2.95],
['mx-tm', 5.47],
['mx-co', 9.46],
['mx-yu', 8.62],
['mx-dg', 4.47],
['mx-gj', 8.33],
['mx-sl', 4.35],
['mx-hg', 4.75]
];
// Create the chart
Highcharts.mapChart('container', {
chart: {
map: 'countries/mx/mx-all'
},
title: {
text: 'Highmaps basic demo'
},
subtitle: {
text: 'Source map: Mexico'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
colorAxis: {
min: 0
},
series: [{
data: data,
name: 'Value',
states: {
hover: {
color: '#BADA55'
}
},
}]
});```
Here's a jsfiddle: https://jsfiddle.net/sstoker/81w2revu/15/
Any help would be very much appreciated!!!
You can add the second series in this way:
series: [{
data: data,
name: 'Value',
...
}, {
name: 'Ranking: ',
data: data2
}]
Live demo: https://jsfiddle.net/BlackLabel/amtycfbL/
But I think that a better solution would be to add the additional data field to the first series data and display it in a tooltip by using pointFormat option:
data.forEach(function(el, i) {
el.push(data2[i][1])
});
// Create the chart
Highcharts.mapChart('container', {
...
tooltip: {
pointFormat: 'Value {point.name} Ranking: {point.rank}'
},
series: [{
keys: ['hc-key', 'value', 'rank'],
data: data,
...
}]
});
Live demo: https://jsfiddle.net/BlackLabel/j809rcva/
API Reference: https://api.highcharts.com/highmaps/series.map.keys
I have bubble chart in highchart plugin,Here my requirement is anyone bubble should be selected based on clicked value.for ex. if I click 10 different selection and if click on 20 different selection will be there.Can anyone please help me on it.Here is my code below.
html
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container" style="min-width: 310px; max-width: 600px; height: 400px; margin: 0 auto;"></div>
<p class="num">10</p>
<p class="num">20</p>
javascript
$("p.num").show();
$("p.num").click(function(){
Highcharts.chart('container', {
chart: {
type: 'bubble',
plotBorderWidth: 1,
zoomType: 'xy',
events:{
load:function(){
var points = this.series[0].points;
points[6].select();
}
}
},
title: {
text: 'Highcharts bubbles with radial gradient fill'
},
xAxis: {
gridLineWidth: 1
},
yAxis: {
startOnTick: false,
endOnTick: false
},
plotOptions: {
series: {
allowPointSelect: true,
marker: {
states: {
select: {
fillColor : 'orange'
}
}
}
}
},
series: [{
data: [
[9, 81, 103],
[98, 5, 89],
[51, 50, 73],
[41, 22, 14],
[58, 24, 20],
[78, 37, 34],
[55, 56, 53],
[18, 45, 70],
[42, 44, 28],
[3, 52, 59],
[31, 18, 97],
[79, 91, 63],
[93, 23, 23],
[44, 83, 22]
],
color: 'green',
}]
})
});
style.css
.highcharts-point-select{
stroke: orange;
}
Of course, you can do it. I have updated the codepen: https://codepen.io/samuellawrentz/pen/mjqmVZ
You just have to pick a point from the series data and then fire the select event on it during chart load. The condition to pick which point to be selected during load must be specified.
For now, I have hard-coded the 6th point to be selected during page load. Check out the codepen for details.
EDIT:
As you requested, I have updated the codepen,have a look. The value to be selected during click is given as a value attribute in the HTML. Then during the click event we are reading that attribute and selecting the point that was mentioned in the value attribute.
<p class="num" value=5>10</p>
Here 5th point will be selected when you click on 10 as the value of the value attribute is 5.
Ref: https://api.highcharts.com/class-reference/Highcharts.Point#select
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 have created fiddle to show my current graph:
http://jsfiddle.net/LLExL/4445/
The code is
$('#container').highcharts({
chart: {
backgroundColor: 'none',
spacingRight: 20,
zoomType: 'x'
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
legend: {
borderWidth: 0,
enabled: true,
verticalAlign: 'top',
y: 25
},
plotOptions: {
series: {
animation: false,
marker: {
enabled: false,
states: {
hover: {
enabled: true,
radius: 5
}
}
}
},
},
title: {
text: 'Points'
},
tooltip: {
shared: true
},
xAxis: {
labels: {
format: '{value: %d/%m}'
},
type: 'datetime'
},
yAxis: {
title: {
text: null
},
showFirstLabel: true
},
series: [{
type: 'column',
name: 'Reached',
data: [
[1427328000000, 198],
[1427414400000, 127],
[1427673600000, 104],
[1427760000000, 107],
[1427846400000, 102],
[1427932800000, 1],
[1428278400000, 1],
[1428364800000, 55],
[1428451200000, 83],
[1428537600000, 77],
[1428624000000, 107],
[1428883200000, 99],
[1428969600000, 140],
[1429056000000, 134],
[1429142400000, 108],
[1429228800000, 104],
[1429488000000, 113],
[1429574400000, 115],
[1429660800000, 115],
[1429747200000, 97],
]
}, {
type: 'line',
name: 'Target',
color: 'red',
lineWidth: 2,
data: [
[1427328000000, 123],
[1427414400000, 123],
[1427673600000, 123],
[1427760000000, 123],
[1427846400000, 143],
[1427932800000, 0],
[1428278400000, 0],
[1428364800000, 143],
[1428451200000, 143],
[1428537600000, 143],
[1428624000000, 114],
[1428883200000, 143],
[1428969600000, 143],
[1429056000000, 143],
[1429142400000, 143],
[1429228800000, 114],
[1429488000000, 143],
[1429574400000, 143],
[1429660800000, 143],
[1429747200000, 143],
]
} ]
});
I want to remove inactive dates from the X-axis, ex. the dates BETWEEN 02/04 and 06/04 (but not these 2, since they have a value).
The only solution I have found working is to declare the dates myself via Categories and then going away from the datetime type axis. This is not the right solution for me tho, since the axis then won't fit correctly on smaller screens.
Is this anyhow possible to remove no-value-dates?
In Highcharts there is no ordinal option for axis, but it can be set if you are using Highstock. This options hides values from x axis that do not have points.
You could use Highstock to create Highcharts chart with axis that have ordinal x axis.
Load Highstock JS file instead of Highcharts:
<script src="http://code.highcharts.com/stock/highstock.js"></script>
In axis options set ordinal to true:
xAxis: {
ordinal: true,
jsFiddle: http://jsfiddle.net/LLExL/4451/