how to make bubble chart in highchart selected a bubble on load - highcharts

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

Related

Highmaps: How do you change the name of a state

I need to change the name of a state in this map from the Highmaps map collection. Specifically, I need to change the name of the "Distrito Federal" to "CDMX". In the series data it is this point: ['mx-df', 10]. I've searched around for an answer, but am having trouble understanding how to do it. Anyone out there able to help?
Here's a link to a JSFiddle: https://jsfiddle.net/sstoker/81w2revu/
Here's the HTML:
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/exporting.js"></script>
<script src="https://code.highcharts.com/mapdata/countries/mx/mx-all.js"></script>
<div id="container"></div>
Here's the JavaScript:
// 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 data = [
['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]
];
// 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: 'Random data',
states: {
hover: {
color: '#BADA55'
}
},
dataLabels: {
enabled: true,
format: '{point.name + }'
}
}]
});
And here's the CSS:
#container {
height: 500px;
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
.loading {
margin-top: 10em;
text-align: center;
color: gray;
}
You can change the displayed information in tooltip and data label by using formatter function:
series: [{
...,
dataLabels: {
enabled: true,
formatter: function() {
if (this.point['hc-key'] === 'mx-df') {
return 'CDMX';
}
return this.point.name;
}
}
}],
tooltip: {
pointFormatter: function() {
if (this['hc-key'] === 'mx-df') {
return 'CDMX: ' + this.value;
}
return this.name + ' ' + this.value;
}
}
Live demo: https://jsfiddle.net/BlackLabel/hry758v3/
API Reference:
https://api.highcharts.com/highmaps/series.map.dataLabels.formatter
https://api.highcharts.com/highmaps/tooltip.pointFormatter

Need drill down with stacked and grouped column chart

I am trying to drilled down on grouped & stacked column chart. I have two group and technically 4 stack in my chart. I want to do drill down on each stack.
Here is my grouped & stacked column chart:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="http://github.highcharts.com/highcharts.js"></script>
<script src="http://github.highcharts.com/modules/drilldown.js"></script>
<script>
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
xAxis: {
categories: ["1/5", "2/5", "3/5", "5/5"]
},
plotOptions: {
series: {
stacking: 'percent'
}
},
series: [
{
id: 'g1',
color: 'blue',
name: "group1",
data: [1, 2, 3, 4],
stack: "move"
},
{
linkedTo: 'g1',
color: 'blue',
name: "group1",
data: [5, 6, 7, 8],
stack: "delete"
},
{
id: 'g2',
color: 'green',
name: "group2",
data: [9, 10, 11, 12],
stack: "move"
},
{
linkedTo: 'g2',
color: 'green',
name: "group2",
data: [13, 14, 15, 16],
stack: "delete"
},
{
id: 'g3',
color: 'red',
name: "group3",
data: [17, 18, 19, 20],
stack: "move"
},
{
linkedTo: 'g3',
color: 'red',
name: "group3",
data: [21, 22, 23, 24],
stack: "delete"
},
{
id: 'g4',
color: 'yellow',
name: "group3",
data: [17, 18, 19, 20],
stack: "move"
},
{
linkedTo: 'g4',
color: 'yellow',
name: "group3",
data: [21, 22, 23, 24],
stack: "delete"
}
]
});
});
</script>
</body>
</html>
But can't understand how to make it drill down. I want to show fixed placement column on drill down like this:
You need to add a drilldown property to points. To add multiple series on drilldown use custom drilldown concept:
series: [{
...,
data: [{
y: 1,
drilldown: true
}, {
y: 2,
drilldown: true
}, ...],
drilldown: true
}, ... ]
Live demo: http://jsfiddle.net/BlackLabel/5a2orf4t/
Docs: https://www.highcharts.com/docs/chart-concepts/drilldown
Similar questions:
Drilldown for grouped column chart in highcharts
https://www.highcharts.com/forum/viewtopic.php?t=34240

highcharts unable to select certain classes

I am trying to select specific elements in order to change the 'stroke' attribute (to change the color).
Strangely, I can select some elements by class, but the one I really need to change, does not appear to be selectable and I can't figure out why.
In the code, there are 3 selections that, currently, simply output the number of elements found and writes that number into a tag.
The 'g.highcharts-button rect' works and writes the appropriate value into the tag.
However, the class I really need to be able to select, 'highcharts-label-box', seems impossible to select.
If anyone could tell me how to select this element I then need to be able to change the 'stroke' attribute to a value of '#ff0000.
I've spent several days on this and I just cannot see how to do this, or why it won't work. Help!
jsfiddle
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Total Asset Allocation</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script>
$(function() {
$('#container').highcharts({
"chart": {
renderTo: 'container',
type: 'area',
marginBottom: 150,
events: {
load: function() {
/*
THE NEXT FEW LINES OF CODE (CURRENTLY COMMENTED OUT) ARE MY ATTEMPT
TO SELECT SPECIFIC CLASSES. AT THE MOMENT, I'M ONLY TRYING TO COUNT
THE FOUND CLASSES AND OUTPUT THEM TO A <p> TAG FOR DEBUGGING.
var g = document.querySelectorAll("g.highcharts-button rect");
document.getElementById("gs").innerHTML = 'gs=' + g.length;
var w = document.querySelectorAll("path.highcharts-label-box");
document.getElementById("ws").innerHTML = 'ws=' + w.length;
var p = document.querySelectorAll('svg g path.highcharts-label-box');
document.getElementById("ps").innerHTML = 'ps=' + p.length;
*/
var locator = document.querySelector('.highcharts-exporting-group');
$(locator).append($('.highcharts-plot-lines-0').detach());
this.renderer.rect(this.plotLeft, this.plotSizeY + this.plotTop + 100, this.plotSizeX, 2)
.css({
fill: '#000',
zIndex: 4
}).add();
this.renderer.rect(this.plotSizeX / 16 * 9.5 + this.plotLeft, this.plotSizeY + this.plotTop + 100 - 5, 2, 12)
.css({
fill: '#000',
zIndex: 4
}).add();
this.renderer.text('Years to Retirement', 250, 480)
.css({
fontSize: 15
}).add();
this.renderer.text('Years Past Retirement', 550, 480)
.css({
fontSize: 15
}).add();
this.renderer.text("\u25b6", this.chartWidth - 21, 467)
.css({
fontSize: 15
}).add();
this.renderer.text('\u2B07', 650, 400)
.css({
fontSize: 10
}).add();
this.renderer.text('MM RetireSMART<br/><span style="color:transparent">...</span>"In Retirement', 615, 414)
.css({
fontSize: 10
}).add();
}
}
},
title: {
text: 'Target Asset Allocation'
},
legend: {
enabled: false
},
xAxis: {
categories: ['45+', 40, 35, 30, 25, 20, 15, 10, 5, 0, 5, 10, 15, 20, 25, '30+'],
tickColor: '#000',
tickWidth: 1,
tickmarkPlacement: 'on',
title: {
enabled: false
},
plotLines: [{
color: '#fff',
width: 5,
visible: true,
value: 9
}]
},
yAxis: {
title: {
text: 'Weighting',
style: {
color: '#000',
fontWeight: 'bold'
}
},
label: {
padding: 50
},
tickmarkPlacement: 'on',
tickInterval: 10,
tickLength: 5,
tickWidth: 1,
tickColor: '#000',
"allowDecimals": false,
gridLineWidth: 0
},
plotOptions: {
area: {
stacking: 'percent',
lineColor: '#fff',
lineWidth: 1,
marker: {
lineWidth: 1,
lineColor: '#fff'
}
},
series: {
events: {
afterAnimate: function() {
var label = this.labelBySeries;
label.attr({
'text-anchor': 'middle',
}).css({
color: this.options.labelColor
})
}
},
marker: {
enabled: false
},
}
},
series: [{
useHTML: true,
name: '<span style="color: transparent;">WWWWWWW</span>Other Funds</span>',
color: '#b0b0b0',
label: {
connectorAllowed: true,
onArea: false,
style: {
color: '#fff',
fontSize: 'large'
}
},
data: [2, 3, 3, 4.5, 3, 3, 3, 2, 5, 3.5, 4, 4, 3, 3, 2, 4]
}, {
name: '<span style="color: transparent;">WWW</span>Fixed Income<br><span style="color:transparent;font-size:3px;">W</span><br/><span style="color: transparent;">WWW</span>Funds',
color: '#010101',
label: {
style: {
fontSize: 'large'
}
},
data: [5, 6, 6, 7, 9, 11, 14, 16, 16, 18, 19, 30, 35, 44, 55, 66]
}, {
name: '<span class="EquityFunds">Equity Funds</span><span style="color: transparent;">WW</span>',
color: '#303030',
label: {
style: {
fontSize: 'large'
}
},
data: [95, 99, 98, 97.5, 90, 80, 70, 60, 40, 33, 22, 20, 17, 15, 13, 11]
}],
});
});
</script>
</head>
<body>
<div id="container" style="width: 800px; height: 510px; margin: 0 auto"></div>
<p id="gs"></p>
<p id="ws"></p>
<p id="ps"></p>
</body>
</html>
You can simply change stroke attribute in series.afterAnimate event:
label.box.attr({
stroke: 'red'
})
The only problem was to find an object (box) that contains connector attributes.
jsFiddle: https://jsfiddle.net/BlackLabel/45hfga0y/
Also, you can do it using your approach. We can get an element with selector path.highcharts-label-box and set attribute like this:
var w = document.querySelectorAll("path.highcharts-label-box");
w[0].setAttribute('stroke', 'red');
But we have to get w element after animate is finished - otherwise, if we do this in chart.load event, the w element will not exist yet.
jsFiddle: https://jsfiddle.net/BlackLabel/5q7feort/
Hope it helps!
Best regards
ps. please, as daniel_s told you before, do not duplicate your questions on a few support channels. You will get your answer anyway.

Highlighting last column in Highcharts

I have a bar chart which has dynamic columns in it.
What i want is that except the last column, all the columns should be of grey color. And the last column should be of green.
Can anyone help me out in this?
You can give color to last column in this way
series: [{
name: 'Test',
color:'grey',
data: [50, 30, 40, 70, {y: 34, color: '#66ff33'}]
}]
Fiddle link
So if the data array is dynamic then for the last value of array you have to make last element as {y: 34, color: '#66ff33'} of the array.
You could use zones.
Demo: http://jsfiddle.net/udL2ads2/6/
$(function() {
var histSuccess = [100, 99, 100, 98, 98, 99.9, 97.5, 100, 95, 90];
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Column chart with last column different color'
},
yAxis: {
min: 0,
title: {
text: 'Total'
}
},
series: [{
name: 'Test',
color: 'grey',
data: histSuccess,
zoneAxis: 'x',
zones: [{
value: histSuccess.length - 1.5,
color: 'grey'
},{
color: '#66ff33'
}]
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

Highcharts polar chart wind rose data from JSON

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>

Resources