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
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 want to do this in Vaadin.
$(function () {
// Create the chart
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Highcharts multi-series drilldown'
},
subtitle: {
text: 'Click columns to drill down to single series. Click categories to drill down both.'
},
xAxis: {
type: 'category'
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true
}
}
},
series: [{
name: '2010',
data: [{
name: 'Republican',
y: 5,
drilldown: 'republican-2010'
}, {
name: 'Democrats',
y: 2,
drilldown: 'democrats-2010'
}, {
name: 'Other',
y: 4,
drilldown: 'other-2010'
}]
}, {
name: '2014',
data: [{
name: 'Republican',
y: 4,
drilldown: 'republican-2014'
}, {
name: 'Democrats',
y: 4,
drilldown: 'democrats-2014'
}, {
name: 'Other',
y: 4,
drilldown: 'other-2014'
}]
}],
drilldown: {
series: [{
id: 'republican-2010',
data: [
['East', 4],
['West', 2],
['North', 1],
['South', 4]
]
}, {
id: 'democrats-2010',
data: [
['East', 6],
['West', 2],
['North', 2],
['South', 4]
]
}, {
id: 'other-2010',
data: [
['East', 2],
['West', 7],
['North', 3],
['South', 2]
]
}, {
id: 'republican-2014',
data: [
['East', 2],
['West', 4],
['North', 1],
['South', 7]
]
}, {
id: 'democrats-2014',
data: [
['East', 4],
['West', 2],
['North', 5],
['South', 3]
]
}, {
id: 'other-2014',
data: [
['East', 7],
['West', 8],
['North', 2],
['South', 2]
]
}]
}
});
});
I am using the asynchronous Drilldown to generate the series:
chart.setDrilldownCallback(new DrilldownCallback() {
private static final long serialVersionUID = 6274915467357292767L;
#Override
public DataSeries handleDrilldown(DrilldownEvent event) {
i++;
return buildDataSeries(event.getItem());
}
});
As you can see handleDrilldown(DrilldownEvent event) returns one DataSeries and I need a list.
Is there any way to add multiple series with drilldown in Vaadin?
I'm not sure why you need a list of DataSeries. You should have enough information in the DrilldownEvent object to know which bar (republican/democrat/other;2010/2014) was selected. Knowing that, you can construct a single DataSeries which contains all four East, West, North, South values. As can be seen the link you submitted, each drilldown is contained within one series "Series 3".
String year = event.getSeries().getName() // 2010 or 2014
String party = event.getDataSeriesItem().getName() // Republican, Democrat or Other
Knowing that you can construct you DataSeries:
DataSeries series = new DataSeries();
series.add(new DataSeriesItem("East", a);
series.add(new DataSeriesItem("West", b);
series.add(new DataSeriesItem("North", c);
series.add(new DataSeriesItem("South", d);
// a, b, c, d depending on the year and party variables above
I would like to have a chart that represent data like this.
the series code would be something like this.
series: [{
name: 'Car 1',
data: [[1, 3], [4, 6], [7, 9]]
}, {
name: 'Car 2',
data: [[2, 3], [8, 10], [12, 18]]
}]
The first number on each array would be the starting point and the second the finishing point, and all arrays inside the main array would be on the same line.
An inverted columnrange chart should work. Your data isn't formatted in a way that would work with what you want, but transforming it isn't difficult. If you aren't stuck with the data format you showed, you just need a point object with x, low, and high.
For example:
{
x: 1,
low: 0,
high: 4
}
The following massages your current structure into the correct format:
$(function () {
var series = [{
name: 'Car 1',
data: [
[1, 3],
[4, 6],
[7, 9]
]
}, {
name: 'Car 2',
data: [
[2, 3],
[8, 10],
[12, 18]
]
}, {
name: 'Car 3',
data: [
[5, 9],
[1, 2]
]
}];
// massage the data
var data = [];
for(var i=0;i<series.length;i++) {
for(var j=0;j<series[i].data.length;j++) {
data.push({
x: j,
low: series[i].data[j][0],
high: series[i].data[j][1],
name: series[i].name
});
}
}
$('#container').highcharts({
chart: {
type: 'columnrange',
inverted: true
},
plotOptions: {
columnrange: {
dataLabels: {
enabled: false
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Cars',
data: data
}]
});
});
http://jsfiddle.net/hqwrx4uy/
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 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>