Change the series title in a Highcharts drill down legend - highcharts

I have created a Highcharts line chart that compares averaged ratings for states for the past ten years. The y axis contains the years and there can be multiple states selected for comparison. Each point on the chart drills down to a bar chart that shows the sub-categories that created the average you see on the principal chart for that particular state on that particular year. This is what I wanted it to do.
But then I noticed, quite by accident, that if I click on one of the years on the y axis, it also drills down and shows a comparison of the sub-categories for each of the states currently appearing on the principal chart for the particular year selected. I really like this feature. However, there is one problem I can't resolve, which is that the legend on this particular drill down doesn't show the names of the states but rather shows all of them as the name of the year that was selected. This is desirable on the drill down from a point on the main chart as there is only ever one state and showing the year is helpful for the user, but here it is confusing. It would be great if on the year drill down the legend would show the names of the selected states.
Can anybody give me some guidance on how to achieve this? Many thanks in advance!
Here's a link to the jsfiddle: https://jsfiddle.net/sstoker/gx5bho9k/424/
Here's the chart code including the first two states (as you'll see in the jdfiddle, there are many more, but I cut them off here for the sake of brevity):
// Create the chart
Highcharts.chart('container', {
chart: {
type: 'line'
},
title: {
text: 'IDD-Mex Indice'
},
yAxis: {
title: {
text: 'Índice'
}
},
xAxis: {
type: 'category'
},
legend: {
enabled: true
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true
}
}
},
series: [{
name: 'Aguascalientes', //Aguascalientes start
data: [{
name: '2010',
y: 7.696,
drilldown: 'ag2010'
}, {
name: '2011',
y: 8.665,
drilldown: 'ag2011'
}, {
name: '2012',
y: 7.110,
drilldown: 'ag2012'
}, {
name: '2013',
y: 4.816,
drilldown: 'ag2013'
}, {
name: '2014',
y: 7.670,
drilldown: 'ag2014'
}, {
name: '2015',
y: 8.026,
drilldown: 'ag2015'
}, {
name: '2017',
y: 9.201,
drilldown: 'ag2017'
}, {
name: '2018',
y: 10.000,
drilldown: 'ag2018'
}]
}, {
name: 'BCN', //BCN Start
data: [{
name: '2010',
y: 6.515,
drilldown: 'bc2010'
}, {
name: '2011',
y: 4.941,
drilldown: 'bc2011'
}, {
name: '2012',
y: 4.369,
drilldown: 'bc2012'
}, {
name: '2013',
y: 4.936,
drilldown: 'bc2013'
}, {
name: '2014',
y: 5.512,
drilldown: 'bc2014'
}, {
name: '2015',
y: 5.066,
drilldown: 'bc2015'
}, {
name: '2017',
y: 1.855,
drilldown: 'bc2017'
}, {
name: '2018',
y: 5.594,
drilldown: 'bc2018'
}],
},
And here is the drilldown code which I cut off here after the same two states as above:
drilldown: {
activeAxisLabelStyle: {
textDecoration: 'none',
fontStyle: 'italic'
},
activeDataLabelStyle: {
textDecoration: 'none',
fontStyle: 'italic'
},
series: [{
id: 'ag2010', //Aguascalientes start
name: '2010',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 5.764],
['Índice Democracia de las Instituciones', 7.601],
['Índice Democracia Social', -0.161],
['Índice Democracia Económica', 0.478],
['Desarrollo Democrático ', 7.696]
]
}, {
id: 'ag2011',
name: '2011',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 6.653],
['Índice Democracia de las Instituciones', 7.087],
['Índice Democracia Social', -0.15],
['Índice Democracia Económica', 0.714],
['Desarrollo Democrático ', 8.665]
]
}, {
id: 'ag2012',
name: '2012',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 6.653],
['Índice Democracia de las Instituciones', 7.087],
['Índice Democracia Social', -0.15],
['Índice Democracia Económica', 0.714],
['Desarrollo Democrático ', 8.665]
]
}, {
id: 'ag2013',
name: '2013',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 3.394],
['Índice Democracia de las Instituciones', 5.054],
['Índice Democracia Social', 0.087],
['Índice Democracia Económica', 0.031],
['Desarrollo Democrático ', 4.816]
]
}, {
id: 'ag2014',
name: '2014',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 6.807],
['Índice Democracia de las Instituciones', 4.860],
['Índice Democracia Social', 0.536],
['Índice Democracia Económica', 0.855],
['Desarrollo Democrático ', 7.670]
]
}, {
id: 'ag2015',
name: '2015',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 6.408],
['Índice Democracia de las Instituciones', 5.181],
['Índice Democracia Social', 0.621],
['Índice Democracia Económica', 1.169],
['Desarrollo Democrático ', 8.026]
]
}, {
id: 'ag2017',
name: '2017',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 5.166],
['Índice Democracia de las Instituciones', 5.980],
['Índice Democracia Social', 0.755],
['Índice Democracia Económica', 1.350],
['Desarrollo Democrático ', 9.201]
]
}, {
id: 'ag2018',
name: '2018',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 6.553],
['Índice Democracia de las Instituciones', 5.319],
['Índice Democracia Social', 0.499],
['Índice Democracia Económica', 1.495],
['Desarrollo Democrático ', 10.000]
]
}, {
id: 'bc2010', //BCN start
name: '2010',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 4.346],
['Índice Democracia de las Instituciones', 4.870],
['Índice Democracia Social', -0.822],
['Índice Democracia Económica', 1.544],
['Desarrollo Democrático', 6.515]
]
}, {
id: 'bc2011',
name: '2011',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 4.274],
['Índice Democracia de las Instituciones', 3.65],
['Índice Democracia Social', 0.861],
['Índice Democracia Económica', 0.262],
['Desarrollo Democrático ', 4.941]
]
}, {
id: 'bc2012',
name: '2012',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 3.401],
['Índice Democracia de las Instituciones', 4.238],
['Índice Democracia Social', 0.529],
['Índice Democracia Económica', 0.056],
['Desarrollo Democrático ', 4.369]
]
}, {
id: 'bc2013',
name: '2013',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 4.297],
['Índice Democracia de las Instituciones', 3.964],
['Índice Democracia Social', 0.907],
['Índice Democracia Económica', 0.671],
['Desarrollo Democrático ', 4.936]
]
}, {
id: 'bc2014',
name: '2014',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 5.565],
['Índice Democracia de las Instituciones', 3.581],
['Índice Democracia Social', 0.696],
['Índice Democracia Económica', -0.008],
['Desarrollo Democrático', 5.512]
]
}, {
id: 'bc2015',
name: '2015',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 5.913],
['Índice Democracia de las Instituciones', 2.833],
['Índice Democracia Social', 0.306],
['Índice Democracia Económica', -0.05],
['Desarrollo Democrático ', 5.066]
]
}, {
id: 'bc2017',
name: '2017',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 2.511],
['Índice Democracia de las Instituciones', 3.621],
['Índice Democracia Social', 0.577],
['Índice Democracia Económica', -0.315],
['Desarrollo Democrático ', 1.855]
]
}, {
id: 'bc2018',
name: '2018',
type: 'bar',
data: [
['Índice Democracia de los Ciudadanos', 5.317],
['Índice Democracia de las Instituciones', 3.764],
['Índice Democracia Social', 0.468],
['Índice Democracia Económica', -0.197],
['Desarrollo Democrático ', 5.594]
]
},

You can use dirlldown and drillup events of chart to change the title.
Fiddle example: https://jsfiddle.net/zar9en0b/
chart: {
type: 'line',
events: {
drilldown: function(e) {
chart.setTitle({ text: e.point.name });
},
drillup: function(e) {
chart.setTitle({ text: 'IDD-Mex Indice'});
}
}
}
API Reference :
http://api.highcharts.com/highcharts#chart.events.drilldown
https://api.highcharts.com/highcharts/chart.events.drillup

Related

Highchart-graph does not appear in internet explorer

I computed a graph in Highcharts which words perfectly well in any browser but internet explorer (see https://jsfiddle.net/statistik_tg/e69Lp3cv/). I had to add a drill down and drill up as the main chart and the drilled down chart include other metrics. Since then, it hasn't been working in IE.
Does anybody know asolution to let the code run in IE, too? Thanks in advance!
$(document).ready(function() {
var chart = {
type: 'column',
marginBottom: 220,
spacingBottom: 85,
events: {
drilldown: function (e) {
if (!e.seriesOptions) {
var chart = this,
drilldowns = {
'Thurgau': {
name: 'Übrige',
color: '#878787',
data: [
['2009', 106],
['2010', 107],
['2011', 102],
['2012', 102],
['2013', 100],
['2014', 102],
['2015', 107],
['2016', 120],
['2017', 121]
]
}
},
drilldowns2 = {
'Thurgau': {
name: 'Phyisotherapie',
color: '#B5B5B5',
data: [
['2009', 79],
['2010', 83],
['2011', 82],
['2012', 85],
['2013', 89],
['2014', 103],
['2015', 115],
['2016', 128],
['2017', 132]
]
}
},
drilldowns3 = {
'Thurgau': {
name: 'Laboratorien',
color: '#E39E00',
data: [
['2009', 42],
['2010', 43],
['2011', 45],
['2012', 48],
['2013', 55],
['2014', 57],
['2015', 63],
['2016', 69],
['2017', 73]
]
}
},
drilldowns4 = {
'Thurgau': {
name: 'Spitex',
color: '#CD3700',
data: [
['2009', 48],
['2010', 49],
['2011', 53],
['2012', 58],
['2013', 62],
['2014', 68],
['2015', 75],
['2016', 80],
['2017', 83]
]
}
},
drilldowns5 = {
'Thurgau': {
name: 'Pflegeheime',
color: '#8B0000',
data: [
['2009', 192],
['2010', 186],
['2011', 182],
['2012', 182],
['2013', 179],
['2014', 169],
['2015', 171],
['2016', 175],
['2017', 173]
]
}
},
drilldowns6 = {
'Thurgau': {
name: 'Apotheken',
color: '#FFED00',
data: [
['2009', 119],
['2010', 121],
['2011', 126],
['2012', 136],
['2013', 141],
['2014', 145],
['2015', 159],
['2016', 178],
['2017', 188]
]
}
},
drilldowns7 = {
'Thurgau': {
name: 'Ärzte Laboranalysen',
color: '#00B4E8',
data: [
['2009', 52],
['2010', 45],
['2011', 46],
['2012', 47],
['2013', 51],
['2014', 54],
['2015', 58],
['2016', 61],
['2017', 62]
]
}
},
drilldowns8 = {
'Thurgau': {
name: 'Ärzte Medikamente',
color: '#0064e6',
data: [
['2009', 339],
['2010', 331],
['2011', 327],
['2012', 329],
['2013', 335],
['2014', 330],
['2015', 342],
['2016', 361],
['2017', 369]
]
}
},
drilldowns9 = {
'Thurgau': {
name: 'Ärzte Behandlung (ohne Labor)',
color: '#27408B',
data: [
['2009', 477],
['2010', 490],
['2011', 509],
['2012', 521],
['2013', 563],
['2014', 586],
['2015', 632],
['2016', 646],
['2017', 655]
]
}
},
drilldowns10 = {
'Thurgau': {
name: 'Spital ambulant',
color: '#a2c510',
data: [
['2009', 474],
['2010', 481],
['2011', 524],
['2012', 533],
['2013', 579],
['2014', 597],
['2015', 602],
['2016', 658],
['2017', 675]
]
}
},
drilldowns11 = {
'Thurgau': {
name: 'Spital stationär',
color: '#3CA433',
data: [
['2009', 724],
['2010', 733],
['2011', 736],
['2012', 727],
['2013', 874],
['2014', 865],
['2015', 844],
['2016', 833],
['2017', 793]
]
}
},
series = drilldowns[e.point.name],
series2 = drilldowns2[e.point.name];
series3 = drilldowns3[e.point.name];
series4 = drilldowns4[e.point.name];
series5 = drilldowns5[e.point.name];
series6 = drilldowns6[e.point.name];
series7 = drilldowns7[e.point.name];
series8 = drilldowns8[e.point.name];
series9 = drilldowns9[e.point.name];
series10 = drilldowns10[e.point.name];
series11 = drilldowns11[e.point.name];
chart.addSingleSeriesAsDrilldown(e.point, series);
chart.addSingleSeriesAsDrilldown(e.point, series2);
chart.addSingleSeriesAsDrilldown(e.point, series3);
chart.addSingleSeriesAsDrilldown(e.point, series4);
chart.addSingleSeriesAsDrilldown(e.point, series5);
chart.addSingleSeriesAsDrilldown(e.point, series6);
chart.addSingleSeriesAsDrilldown(e.point, series7);
chart.addSingleSeriesAsDrilldown(e.point, series8);
chart.addSingleSeriesAsDrilldown(e.point, series9);
chart.addSingleSeriesAsDrilldown(e.point, series10);
chart.addSingleSeriesAsDrilldown(e.point, series11);
chart.applyDrilldown();
chart.yAxis[0].update({
min: 0,
max: 4000
})
}
},
drillup(){
this.yAxis[0].update({
min: 0,
max: 100
})
}
}
};
var plotOptions = {
column: {
stacking: 'normal'
}
};
var title = {
text: "Fast die Hälfte der Kosten im Kanton Thurgau für Spitalbehandlungen",
style: {
fontSize: '18px',
},
align: 'left'
};
var subtitle = {
text: 'Struktur der Bruttokosten nach Kostengruppe, Kanton Thurgau und Schweiz, 2017, Anteile in %/CHF pro versicherte Person¹',
style: {
fontSize: '12px'
},
align: 'left'
};
var yAxis = {
gridLineWidth: 1,
title: '',
lineWidth: 1,
max: 100
};
var xAxis = {
type: 'category'
};
var tooltip = {
valueSuffix: ' CHF'
};
var series = [{
name: 'Übrige',
tooltip: {
valueSuffix: ' %'
},
color: '#878787',
data: [{
name: 'Thurgau',
y: 3.7,
drilldown: true
},{
name: 'Schweiz',
y: 3.5,
drilldown: false
}]
},{
name: 'Physiotherapie',
tooltip: {
valueSuffix: ' %'
},
color: '#B5B5B5',
data: [{
name: 'Thurgau',
y: 4.0,
drilldown: true
},{
name: 'Schweiz',
y: 3.1,
drilldown: false
}]
},{
name: 'Laboratorien',
color: '#E39E00',
tooltip: {
valueSuffix: ' %'
},
data: [{
name: 'Thurgau',
y: 2.2,
drilldown: true
},{
name: 'Schweiz',
y: 2.8,
drilldown: false
}]
},{
name: 'Spitex',
color: '#CD3700',
tooltip: {
valueSuffix: ' %'
},
data: [{
name: 'Thurgau',
y: 2.5,
drilldown: true
},{
name: 'Schweiz',
y: 2.7,
drilldown: false
}]
},{
name: 'Pflegeheime',
tooltip: {
valueSuffix: ' %'
},
color: '#8B0000',
data: [{
name: 'Thurgau',
y: 5.2,
drilldown: true
},{
name: 'Schweiz',
y: 5.7,
drilldown: false
}]
},{
name: 'Apotheken',
tooltip: {
valueSuffix: ' %'
},
color: '#FFED00',
data: [{
name: 'Thurgau',
y: 5.7,
drilldown: true
},{
name: 'Schweiz',
y: 11.8,
drilldown: false
}]
},{
name: 'Ärzte Laboranalysen',
tooltip: {
valueSuffix: ' %'
},
color: '#00B4E8',
data: [{
name: 'Thurgau',
y: 1.9,
drilldown: true
},{
name: 'Schweiz',
y: 1.7,
drilldown: false
}]
},{
name: 'Ärzte Medikamente',
tooltip: {
valueSuffix: ' %'
},
color: '#0064e6',
data: [{
name: 'Thurgau',
y: 11.1,
drilldown: true
},{
name: 'Schweiz',
y: 6.3,
drilldown: false
}]
},{
name: 'Ärzte Behandlungen (ohne Labor)',
tooltip: {
valueSuffix: ' %'
},
color: '#27408B',
data: [{
name: 'Thurgau',
y: 19.7,
drilldown: true
},{
name: 'Schweiz',
y: 22.6,
drilldown: false
}]
},{
name: 'Spital ambulant',
tooltip: {
valueSuffix: ' %'
},
color: '#a2c510',
data: [{
name: 'Thurgau',
y: 20.3,
drilldown: true
},{
name: 'Schweiz',
y: 19.1,
drilldown: false
}]
},{
name: 'Spital stationär',
tooltip: {
valueSuffix: ' %'
},
color: '#3CA433',
data: [{
name: 'Thurgau',
y: 23.8,
drilldown: true
},{
name: 'Schweiz',
y: 20.7,
drilldown: false
}]
}];
var drilldown = {
series: []
};
var legend = {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
padding: 25,
symbolPadding: 10,
symbolWidth: 25,
margin: -10,
/*maxHeight: 150,*/
alignColumns: false,
reversed: false,
itemStyle: {
fontWeight: 'normal'
}
};
var credits = {
text: '<b>Hinweis: Für den Vergleich der Kostenanteile im Kanton Thurgau von 2009-2017 klicken Sie <br><b>auf den Balken oder die Balkenbeschriftung zum Thurgau<br>¹ Vergleich Thurgau-Schweiz Anteile in %, Vergleich Thurgau 2009-2017 Anteile in CHF<br>Dienststelle für Statistik Kanton Thurgau <br>Datenquellen: Bundesamt für Gesundheit, Monitoring der Krankenversicherungs-<br>Kostenentwicklung',
href: false,
style: {
color:'#999999',
cursor: false,
fontSize:'10px'
},
position: {
align: 'left',
x: 10,
y: -90
}
};
var exporting = {
allowHTML: true,
enabled: true,
filename:'2019_07_Krankenversicherungskosten_Brutto_2017',
buttons: {
contextButton: {
menuItems: "printChart separator downloadPNG downloadJPEG downloadSVG".split(" ")
}
},
/*csv: {
columnHeaderFormatter: function (item) {
if(item instanceof Highcharts.Axis) {
return 'Quartal';
} else {
if(item instanceof Highcharts.Series) {
return item.name;
}
}
}
}*/
};
var responsive = {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
enabled: false
}
}
}]
};
var highchartsOptions = Highcharts.setOptions ({
lang: {
decimalPoint: '.',
thousandsSep: "'",
months: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
weekdays: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
shortMonths: ['Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
contextButtonTitle: 'Drucken, Download, Export',
downloadJPEG: 'Download JPEG Bild',
downloadPNG: 'Download PNG Bild',
downloadSVG: 'Download SVG Vektor Bild',
downloadXLS: 'Download XLS',
printChart: 'Bild drucken',
viewData: 'Datentabelle ein-/ausblenden',
resetZoom: "Zoom zurücksetzen",
resetZoomTitle: "Zoom zurücksetzen",
drillUpText: "Zurück",
numericSymbols: null //otherwise by default ['k', 'M', 'G', 'T', 'P', 'E']
}
});
colors = ["#878787","#B5B5B5","#E39E00","#CD3700","#8B0000","#3CA433","#a2c510","#FFED00","#00B4E8","#0064e6","#27408B"]
var json = {};
json.chart = chart;
json.plotOptions = plotOptions;
json.title = title;
json.subtitle = subtitle;
json.yAxis = yAxis;
json.xAxis = xAxis;
json.tooltip = tooltip;
json.series = series;
json.drilldown = drilldown;
json.legend = legend;
json.credits = credits;
json.exporting = exporting;
json.responsive = responsive;
json.highchartsOptions = highchartsOptions;
json.colors = colors;
$('#2019_07_Krankenversicherungskosten_Brutto_2017').highcharts(json);
});
There is an error in IE developer tools console - you need to change JS line 230 from this:
drillup(){
into this:
drillup: function() {
and then it works fine in IE11

Coloring Country while showing mappoint for cities in world map using highmaps

I am working with highmaps and have plotted the cities with map-points using lat-long for the same.
Now , I want to color particular countries say India and USA .
Is there any way to achieve the same ?
Below is my js file for plotting world map with citis mappoints with help of lat/lon
// Initiate the chart
$.getJSON("/MyProject/HighChartPhp/getMapData.php", function (data) {
// Correct UK to GB in data
$.each(data, function () {
if (this.code === 'UK') {
this.code = 'GB';
}
});
//console.log(data);
var final_array = [];
for(var i in data[0].data)
{
var map_data = {
name: data[0].name[i],
lat: data[0].lat[i],
lon: data[0].lon[i],
z: data[0].data[i],
val: data[0].loc[i],
color: data[0].color[i]
}
//console.log(map_data);
final_array[i] = map_data;
}
console.log(final_array);
Highcharts.mapChart('container', {
chart: {
borderWidth: 1,
map: 'custom/world'
},
title: {
text: 'Word Wide Data Usage'
},
subtitle: {
text: ''
},
tooltip: {
headerFormat: '',
pointFormat: '<b>{point.val}</b><br/>{point.z}'
},
legend: {
enabled: false
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
series: [{
// Use the gb-all map with no data as a basemap
mapData: Highcharts.maps['custom/world'],
name: 'Basemap',
borderColor: 'green',
nullColor: 'rgba(200, 200, 200, 0.3)',
showInLegend: true
}, {
// Specify points using lat/lon
type: 'mappoint',
name: 'Cities',
//color: 'blue',
data: final_array
}]
});
});
How can I color India and US in the map ?
Tried the below , but still it is not working .
// Initiate the chart
$.getJSON("/MyProject/HighChartPhp/getMapData.php", function (data) {
// Correct UK to GB in data
$.each(data, function () {
if (this.code === 'UK') {
this.code = 'GB';
}
});
data.forEach(function(point, index) {
console.log("country="+point.country);
if (point.country === 'India' || point.country === 'United States') {
point.color = 'green';
}
});
//console.log(data);
var final_array = [];
for(var i in data[0].data)
{
var map_data = {
name: data[0].name[i],
lat: data[0].lat[i],
lon: data[0].lon[i],
z: data[0].data[i],
val: data[0].loc[i],
color: data[0].color[i],
country:data[0].country[i]
}
//console.log(map_data);
final_array[i] = map_data;
}
console.log(final_array);
Highcharts.mapChart('container', {
chart: {
borderWidth: 1,
map: 'custom/world'
},
title: {
text: 'Word Wide outsource Vendor Usage'
},
subtitle: {
text: ''
},
colorAxis: {
min: 1,
max: 1000,
type: 'logarithmic'
},
tooltip: {
headerFormat: '',
pointFormat: '<b>{point.val}</b><br/>{point.z}'
},
legend: {
enabled: false
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
series: [{
// Use the gb-all map with no data as a basemap
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'code'],
name: 'Basemap',
borderColor: 'green',
nullColor: 'rgba(200, 200, 200, 0.3)',
showInLegend: true
}, {
// Specify points using lat/lon
type: 'mappoint',
name: 'Cities',
//color: 'blue',
data: final_array
}]
});
});
Below is json data :
"name": [
"Ahemdabad",
"Atlanta",
"Bangalore",
"Bangkok",
"Buenos Aires",
"Chennai",
"Chicago",
"Cochin",
"Colombo",
"Dallas",
"Delhi",
"Hyderabad",
"Irvine",
"Irvine Dallas",
"Johannesburg",
"Kolkata",
"Kuala Lumpur",
"Lima",
"Los Angeles",
"Miami",
"Moscow",
"Mumbai",
"New Jersey",
"New York",
"Niagra",
"Philadelphia",
"Rio",
"Riyadh",
"Seattle",
"Syracuse",
"Washington Baltimore"
],
"loc": [
"Ahemdabad:India",
"Atlanta:USA",
"Bangalore:India",
"Bangkok:Thailand",
"Buenos Aires:Argentina",
"Chennai:India",
"Chicago:USA",
"Cochin:India",
"Colombo:Sri Lanka",
"Dallas:USA",
"Delhi:India",
"Hyderabad:India",
"Irvine:USA",
"Irvine Dallas:USA",
"Johannesburg:South Africa",
"Kolkata:India",
"Kuala Lumpur:Malaysia",
"Lima:Peru",
"Los Angeles:USA",
"Miami:USA",
"Moscow:Russia",
"Mumbai:India",
"New Jersey:USA",
"New York:USA",
"Niagra:USA",
"Philadelphia:USA",
"Rio:Brazil",
"Riyadh:Saudi Arabia",
"Seattle:USA",
"Syracuse:USA",
"Washington Baltimore:USA"
],
"color": [
"#FFC300",
"#EC32BF",
"#FFC300",
"#EC32BF",
"#49EC32",
"#FFC300",
"#EC3246",
"#FFC300",
"#EC32BF",
"#EC3246",
"#EC32BF",
"#FFC300",
"#EC32BF",
"#16F7EC ",
"#EC32BF",
"#FFC300",
"#EC32BF",
"#FFC300",
"#581845",
"#EC32BF",
"#EC32BF",
"#FFC300",
"#EC32BF",
"#EC32BF",
"#3A32EC",
"#EC32BF",
"#49EC32",
"#EC32BF",
"#EC32BF",
"#EC32BF",
"#EC32BF"
],
"lat": [
23.022505,
33.748995,
12.971599,
13.756331,
-34.603684,
13.08268,
41.878114,
9.931233,
6.927079,
32.776664,
28.704059,
17.385044,
33.684567,
33.684567,
-26.204103,
22.572646,
3.139003,
-12.046373,
34.052234,
25.76168,
55.755826,
19.075984,
40.058324,
40.712784,
43.082816,
39.952584,
-22.906847,
24.713552,
47.606209,
43.048122,
39.177404
],
"lon": [
72.571362,
-84.387982,
77.594563,
100.501765,
-58.381559,
80.270718,
-87.629798,
76.267304,
79.861243,
-96.796988,
77.10249,
78.486671,
-117.826505,
-117.826505,
28.047305,
88.363895,
101.686855,
-77.042754,
-118.243685,
-80.19179,
37.6173,
72.877656,
-74.405661,
-74.005941,
-79.074163,
-75.165222,
-43.172896,
46.675296,
-122.332071,
-76.147424,
-76.668392
],
"country": [
"India",
"USA",
"India",
"Thailand",
"Argentina",
"India",
"USA",
"India",
"Sri Lanka",
"USA",
"India",
"India",
"USA",
"USA",
"South Africa",
"India",
"Malaysia",
"Peru",
"USA",
"USA",
"Russia",
"India",
"USA",
"USA",
"USA",
"USA",
"Brazil",
"Saudi Arabia",
"USA",
"USA",
"USA"
]
}
You can add property to specific points from the data, before joining with mapData.
API Reference:
http://api.highcharts.com/highmaps/series%3Cmappoint%3E.data.color
Example:
http://jsfiddle.net/0Lcwn3pj/

Rails json/jbuilder - Group json view based on category

I have an web application maded in RoR.
I need to provide the json to an mobile App.
This is my code to generate the Json:
json.category do
json.name monument.category.name
json.monumento do
json.name monument.name
json.id monument.id
json.pois monument.pois do |p|
json.name p.name
end
end
end
The output is:
{
"category": {
"name": "Igrejas",
"monumento": {
"name": "Igreja de Santa Maria do Olival",
"id": 2,
"pois": [{
"name": "Igreja de Santa Maria do Olival"
}]
}
}
},
{
"category": {
"name": "Igrejas",
"monumento": {
"name": "Igreja de São João Baptista",
"id": 3,
"pois": [{
"name": "Igreja de São João Baptista"
}]
}
}
},
{
"category": {
"name": "Igrejas",
"monumento": {
"name": "Igreja da Nossa Senhora da Graça",
"id": 4,
"pois": [{
"name": "Igreja da Nossa Senhora da Graça"
}]
}
}
},
My Problem is that i need to group the categories.
something like this:
{
"category": {
"name": "Igrejas",
"monumento": {
"name": "Igreja de Santa Maria do Olival",
"id": 2,
"pois": [{
"name": "Igreja de Santa Maria do Olival"
}]
},
"monumento": {
"name": "Igreja de São João Baptista",
"id": 3,
"pois": [{
"name": "Igreja de São João Baptista"
}]
},
"monumento": {
"name": "Igreja da Nossa Senhora da Graça",
"id": 4,
"pois": [{
"name": "Igreja da Nossa Senhora da Graça"
}]
}
}
},
Any ideas how can i solve this problem?
You need to do something like this
In your controller,
#categories = Category.where(name: 'Igrejas').includes(monuments: :pois)
In your view,
json.category #categories do |category|
json.name category.name
json.monuments category.monuments do |monument|
json.name monument.name
json.id monument.id
json.pois monument.pois do |p|
json.name p.name
end
end
end

Highchart points not set to y asix

I setting data to highchart with razor syntax like this :
series: [
#foreach (var item in Model)
{
<text>
{
name: '#item.name',
data: [
#foreach (var item2 in item.finalChart)
{
#:[Date.parse("#item2.date1"), #item2.value],
}
]
},
</text>
}
]
And here is executed code:
series: [
{
name: 'clicks6',
data: [
[Date.parse("04/03/2017"), 10],
[Date.parse("04/04/2017"), 45],
]
},
{
name: 'clicks4',
data: [
[Date.parse("04/03/2017"), 28],
[Date.parse("04/04/2017"), 22],
]
},
{
name: 'clicks8',
data: [
[Date.parse("04/03/2017"), 8],
[Date.parse("04/04/2017"), 35],
[Date.parse("04/05/2017"), 5],
[Date.parse("04/10/2017"), 0],
]
},
]
As you can see in below points not adapted with y axis.
If I add another format of data this problem doesn't happend
series: [{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
},{
name: 'Other',
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
}]
How can fix this issue? with some reasons I can't use another format of data.
UPDATE:
It is desired mode that I want:
add UTC to each date input Date.parse("04/03/2017" + ' UTC')
#:[Date.parse("#item2.date1" + ' UTC'), #item2.value],
xAxis will be
xAxis: {
type: 'datetime',
tickInterval: 24 * 3600 * 1000 //this is for one day
},
Highcharts.chart('container', {
chart: {
type: 'spline',
zoomType: 'x'
},
title: {
text: 'Highcharts'
},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
},
xAxis: {
type: 'datetime',
tickInterval: 24 * 3600 * 1000
},
yAxis: {
title: {
text: 'Snow Depth'
},
},
series: [{
name: 'clicks6',
data: [
[Date.parse("04/03/2017" + ' UTC'), 10],
[Date.parse("04/04/2017" + ' UTC'), 45],
]
},
{
name: 'clicks4',
data: [
[Date.parse("04/03/2017" + ' UTC'), 28],
[Date.parse("04/04/2017" + ' UTC'), 22],
]
},
{
name: 'clicks8',
data: [
[Date.parse("04/03/2017" + ' UTC'), 8],
[Date.parse("04/04/2017" + ' UTC'), 35],
[Date.parse("04/05/2017" + ' UTC'), 5],
[Date.parse("04/10/2017" + ' UTC'), 0],
]
},
]
});
<script src="https://code.jquery.com/jquery-3.1.1.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>

Creating ranking chart in Higcharts with bar range colors

I'm trying to create a ranking chart like this :
ranking chart
Where the color of the bar depends on the % of achievement from 0% to 100% in a test.
I cant find the way to use the same serie for different bar colors, and create a multi label legend with only 1 serie. I want to press the legend and show only the bars of that color.
EDIT:
Just figured our how to paint each bar, im OK formatting the data before creating my chart.
I will paste the new code, I only need to add the legend with any color info and filter.
CODE
$(function () {
$('#container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Ranking alumnos'
},
subtitle: {
text: 'El color de la barra indica el nivel de logro'
},
xAxis: {
categories: ['Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo','Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo', 'Alumno de ejemplo'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Logro total %',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' %'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'bottom',
x: -40,
y: 80,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Logro %',
data: [
{y: 100 , color: '#aaff99'},
{y: 98, color: '#aaff99'},
{y: 95 , color: '#aaff99'},
{y: 90, color: '#aaff99'},
{y: 85 , color: '#aaff99'},
{y: 84, color: '#aaff99'},
{y: 83 , color: '#aaff99'},
{y: 82, color: '#aaff99'},
{y: 81, color: '#aaff99'},
{y: 81 , color: '#aaff99'},
{y: 75, color: 'yellow'},
{y: 75 , color: 'yellow'},
{y: 74, color: 'yellow'},
{y: 73 , color: 'yellow'},
{y: 70, color: 'yellow'},
{y: 65, color: 'yellow'},
{y: 64 , color: 'yellow'},
{y: 61, color: 'yellow'},
{y: 61 , color: 'yellow'},
{y: 61, color: 'yellow'} ,
{y: 60, color: 'orange'},
{y: 60 , color: 'orange'},
{y: 58, color: 'orange'},
{y: 56 , color: 'orange'},
{y: 54, color: 'orange'},
{y: 53, color: 'orange'},
{y: 53 , color: 'orange'},
{y: 51, color: 'orange'},
{y: 51 , color: 'orange'},
{y: 51, color: 'orange'},
{y: 50, color: 'red'},
{y: 50 , color: 'red'},
{y: 49, color: 'red'},
{y: 48 , color: 'red'},
{y: 48, color: 'red'},
{y: 48, color: 'red'},
{y: 46 , color: 'red'},
{y: 46, color: 'red'},
{y: 46 , color: 'red'},
{y: 46, color: 'red'}
]
}]
});
});
http://jsfiddle.net/re0q5fnv/
I appreciate your help.
Something like.. (i tried it in your jsfiddle)
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'bottom',
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
}
series: [{
name: 'Logro orange %',
color: 'red'
},{
name: 'Logro orange %',
color: 'orange'
},{
name: 'Logro yellow %',
color: 'yellow',
data: [ <your data>]
}
]

Resources