I am trying to slide both the inner and other donut out when the inner donut is clicked. In the below link only inner donut is sliced out.
http://jsfiddle.net/bvL0r6tq/
I tried to select the outer slice through point select but they do not move out together. The outer ones spread between themselves.
can anyone please let me know how slice both the inner & outer donut out when the inner donut is clicked without spreading the outer donut among themeselves.
var colors = Highcharts.getOptions().colors,
categories = ['MSIE', 'Firefox', 'Chrome', 'Safari', 'Opera'],
data = [{
y: 56.33,
color: colors[0],
drilldown: {
name: 'MSIE versions',
categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0', 'MSIE 10.0', 'MSIE 11.0'],
data: [1.06, 0.5, 17.2, 8.11, 5.33, 24.13],
color: colors[0]
}
}, {
y: 10.38,
color: colors[1],
drilldown: {
name: 'Firefox versions',
categories: ['Firefox v31', 'Firefox v32', 'Firefox v33', 'Firefox v35', 'Firefox v36', 'Firefox v37', 'Firefox v38'],
data: [0.33, 0.15, 0.22, 1.27, 2.76, 2.32, 2.31, 1.02],
color: colors[1]
}
}, {
y: 24.03,
color: colors[2],
drilldown: {
name: 'Chrome versions',
categories: ['Chrome v30.0', 'Chrome v31.0', 'Chrome v32.0', 'Chrome v33.0', 'Chrome v34.0',
'Chrome v35.0', 'Chrome v36.0', 'Chrome v37.0', 'Chrome v38.0', 'Chrome v39.0', 'Chrome v40.0', 'Chrome v41.0', 'Chrome v42.0', 'Chrome v43.0'
],
data: [0.14, 1.24, 0.55, 0.19, 0.14, 0.85, 2.53, 0.38, 0.6, 2.96, 5, 4.32, 3.68, 1.45],
color: colors[2]
}
}, {
y: 4.77,
color: colors[3],
drilldown: {
name: 'Safari versions',
categories: ['Safari v5.0', 'Safari v5.1', 'Safari v6.1', 'Safari v6.2', 'Safari v7.0', 'Safari v7.1', 'Safari v8.0'],
data: [0.3, 0.42, 0.29, 0.17, 0.26, 0.77, 2.56],
color: colors[3]
}
}, {
y: 0.91,
color: colors[4],
drilldown: {
name: 'Opera versions',
categories: ['Opera v12.x', 'Opera v27', 'Opera v28', 'Opera v29'],
data: [0.34, 0.17, 0.24, 0.16],
color: colors[4]
}
}, {
y: 0.2,
color: colors[5],
drilldown: {
name: 'Proprietary or Undetectable',
categories: [],
data: [],
color: colors[5]
}
}],
browserData = [],
versionsData = [],
i,
j,
dataLen = data.length,
drillDataLen,
brightness;
// Build the data arrays
for (i = 0; i < dataLen; i += 1) {
// add browser data
browserData.push({
sliced: categories[i] == 'MSIE' ? true : false,
name: categories[i],
y: data[i].y,
color: data[i].color
});
// add version data
drillDataLen = data[i].drilldown.data.length;
for (j = 0; j < drillDataLen; j += 1) {
brightness = 0.2 - (j / drillDataLen) / 5;
versionsData.push({
name: data[i].drilldown.categories[j],
y: data[i].drilldown.data[j],
color: Highcharts.Color(data[i].color).brighten(brightness).get()
});
}
}
// Create the chart
Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: 'Browser market share, January, 2015 to May, 2015'
},
subtitle: {
text: 'Source: netmarketshare.com'
},
yAxis: {
title: {
text: 'Total percent market share'
}
},
plotOptions: {
pie: {
shadow: false,
center: ['50%', '50%'],
slicedOffset: 20
}
},
tooltip: {
valueSuffix: '%'
},
series: [{
name: 'Browsers',
data: browserData,
size: '0%',
dataLabels: {
formatter: function () {
return this.y > 5 ? this.point.name : null;
},
color: '#ffffff',
distance: -30
}
}, {
name: 'Versions',
data: versionsData,
size: '80%',
innerSize: '60%',
dataLabels: {
formatter: function () {
// display only if larger than 1
return this.y > 1 ? '<b>' + this.point.name + ':</b> ' + this.y + '%' : null;
}
}
}]
});
Thanks,
Sarath
It is not possible with current implementation of sliced property. However, you can achieve that functionality with some effort. You need to move slices which have same browser as they would be one point.
Split your data to inner series and outer series - one outer series per browser type. An outer series should have invisible points so you will have only part of the pie visible.
series: [{
name: 'Browsers',
keys: ['y'],
data: [40, 30, 30],
size: '80%',
innerSize: 0,
slicedOffset: 20,
colorByPoint: true
}, {
data: [20, 20, {
y: 60,
visible: false
}]
}, {
color: colors[1],
data: [{
y: 40,
visible: false
}, 10, 10, 10, {
y: 30,
visible: false
}]
}, {
color: colors[2],
data: [{
y: 70,
visible: false
}, 5, 5, 5, 15]
}]
On click event you need to update center of the correct outer series - the translation for the center should be equaled translation of the sliced point.
const translateSeries = function(series, center, translation) {
const cx = center[0],
cy = center[1];
series.update({
center: [cx + translation.translateX, cy + translation.translateY]
});
};
const translate = function(e) {
const innerSeries = this.chart.series[0];
let point, series;
if (this !== innerSeries) {
point = innerSeries.data[this.index - 1];
series = this;
} else {
point = e.point;
series = this.chart.series[point.index + 1];
}
point.update({
sliced: true
}, false);
translateSeries(series, innerSeries.center, point.slicedTranslation)
};
Live example and output
const colors = Highcharts.getOptions().colors;
const translateSeries = function(series, center, translation) {
const cx = center[0],
cy = center[1];
series.update({
center: [cx + translation.translateX, cy + translation.translateY]
});
};
const translate = function(e) {
const innerSeries = this.chart.series[0];
let point, series;
if (this !== innerSeries) {
point = innerSeries.data[this.index - 1];
series = this;
} else {
point = e.point;
series = this.chart.series[point.index + 1];
}
point.update({
sliced: true
}, false);
translateSeries(series, innerSeries.center, point.slicedTranslation)
};
Highcharts.chart('container', {
chart: {
type: 'pie'
},
plotOptions: {
pie: {
ignoreHiddenPoint: false,
slicedOffset: 0,
size: '80%',
innerSize: '60%',
colorByPoint: false,
dataLabels: {
enabled: false
},
events: {
click: translate
}
}
},
series: [{
name: 'Browsers',
keys: ['y'],
data: [40, 30, 30],
size: '80%',
innerSize: 0,
slicedOffset: 20,
colorByPoint: true
}, {
data: [20, 20, {
y: 60,
visible: false
}]
}, {
color: colors[1],
data: [{
y: 40,
visible: false
}, 10, 10, 10, {
y: 30,
visible: false
}]
}, {
color: colors[2],
data: [{
y: 70,
visible: false
}, 5, 5, 5, 15]
}]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px; width: 500"></div>
Related
I have a nice gauge that displays a percentage value like so:
The options are:
{
title: false,
legend: false,
chart: {
type: 'solidgauge',
width: 150,
height: 150,
},
pane: {
size: '100%',
startAngle: 0,
background: {
backgroundColor: '#eee',
outerRadius: '100%',
innerRadius: '60%',
borderWidth: 0,
shape: 'arc',
},
},
tooltip: {
enabled: false
},
credits: {
enabled: false
},
yAxis: {
min: 0,
max: 100,
lineWidth: 0,
minorTickInterval: null,
tickPixelInterval: 400,
tickWidth: 0,
title: {
enabled: false,
},
labels: {
enabled:false
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: -15,
borderWidth: 0,
format: '{y}%',
style: {
fontSize: '1rem',
fontWeight: 'normal',
}
},
}
},
series: [{
data: [{
y: 75,
color: cyan,
}]
}]
}
But now I need two values:
I'd have expected to add some stacking option somewhere, along with something like:
series: [{
data: [{
y: 10,
color: blue,
}, {
y: 65,
color: cyan,
}]
}]
but it doesn't work. And I haven't found any example for this use-case over the internet either. :(
How can I achieve this?
There is no stacking option for soliidgague. You need to count expected values by yourself to achieve the effect from provided image:
series: [{
data: [{
y: 75,
color: 'cyan',
},
{
y: 15,
color: 'blue',
}]
}]
Demo:
https://jsfiddle.net/BlackLabel/4zq6ehfj/
As #magdalena said, unfortunately there is no stacking option in a solidgauge chart :(
I succeeded to fake this by applying the following transformation:
const absoluteValues = [{
y: 75,
color: 'cyan',
},
{
y: 15,
color: 'blue',
}];
const options = {
series: [{
name: 'My serie',
data: [].concat(absoluteValues).reduce((acc, val) => {
return [...acc, {
...val,
y: acc.reduce((result, {y}) => result + y, val.y),
}]
}, []).reverse()
}],
};
series: [
{
name: 'Operating Systems',
data: [{ y: 10, color: white, }]
size: '60%'
},
{
name: 'Browsers',
data: [{ y: 10, color: blue, }],
size: '80%',
}, {
name: 'Versions',
data: [{ y: 65, color: cyan, }],
size: '100%',
}]
Im doing a chart with 2 series. One of the series is 'scatter' type and the other is 'column' type.
The problem i have, is that when i only have the scatter series, datetime labels on x axis, starts on the extreme left, but when i add the column series, is like all labels are pushed to the center, and i dont know why.
This is my fiddle examen: https://jsfiddle.net/cswpgq8u/7/
Highcharts.chart('container', {
chart: {
},
xAxis: {
type: 'datetime',
min: 1633057200000,
max: 1634353200000,
tickPositioner: function () {
var ticklist = [];
var extremes = this.getExtremes();
var startDate = extremes.min;//this.min;
var endDate = extremes.max; // this.max;
var diff = moment.duration(endDate - startDate);
if (diff.days() * 1 > 10)
increment = moment.duration(2, 'days').asMilliseconds();
else
increment = Math.ceil((endDate - startDate) / 10);
for (var timeline = startDate; moment(timeline) <= moment(endDate); timeline += increment) {
ticklist.push(timeline);
}
return ticklist;
},
maxPadding: 0,
minPadding: 0,
crosshair: {
enabled: true,
events: {
}
},
plotLines: [{
value: 1634266800000,
color: 'green',
width: 1,
dashStyle: 'ShortDash',
label: {
text: "AHORA", // Content of the label.
verticalAlign: 'bottom',
rotate: -90,
textAlign: 'right',
x: -2,
y: 30,
style: { color: '#6d6d6d', fontSize: '8px', fontWeight: 'bold', backgroundColor: 'white' }
},
}],
plotBands: null,
labels: {
formatter: function () {
var xMin = this.axis.min;
var xMax = this.axis.max;
var labeltick = Highcharts.dateFormat('%d. %B', this.value);
if ((moment(xMax).diff(moment(xMin), 'days')) < 10) {
labeltick = Highcharts.dateFormat('%d. %B %H:%M:%S', this.value);
}
return labeltick;
},
x: -10
}
},
yAxis:[
{
plotLines: [{
id: 'ln-' + 'idEje1',
color: '#9FA0A2',
width: 0,
value: 0,
dashStyle: 'longdashdot'
}],
labels: {
enabled:true,
x: -5,
y: -3,
},
title: {
enabled: false,
},
lineColor: 'lightgray',
lineWidth: 0,
tickInterval: 1
}, {
title: {
enabled: false,
},
lineColor: 'lightgray',
opposite: true,
labels: {
enabled: false,
x: -15,
y: -3,
},
lineWidth: 0,
tickInterval: 1
}
],
plotOptions: {
},
series: [
{
yAxis: 0,
type: 'scatter',
minPointLength: 1,
allowPointSelect: false,
stack: true,
data: [{
x: 1634007600000,
y: 2,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
},
{
x: 1633748400000,
y: 5,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
},
{
x: 1633143600000,
y: 2,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
},
{
x: 1633402800000,
y: 2,
value: 2,
marker: {
symbol: 'circle',
radius: 3,
fillColor: 'red',
},
type: "ttf"
}],
name: 'On YAxis 0',
tooltip: {
pointFormatter: function () {
var point = this;
return "Valor TTF:" + ' <b>' + point.y + ' Días</b><br/>';
},
}
},
{
yAxis: 1,
type: 'column',
allowPointSelect: false,
minPointLength: 1,
data: [{
x: 1633708800000,
y: 5,
type: "duracion",
value: 5
},
{
x: 1633881600000,
y: 3,
type: "duracion",
value: 3
}],
name: 'On YAxis1',
tooltip: {
pointFormatter: function () {
var point = this;
return "Duración:" + ' <b>' + point.y + ' minutos</b><br/>';
},
},
pointWidth: 1
}
]
});
With 2 series
With one series
I think this is happening because Column Series. But dont know how to solve it.
The additional space is caused by the default calculation of pointRange for column series. You need to define it by yourself:
series: [{
type: 'scatter',
...
},
{
type: 'column',
pointRange: 1,
...
}
]
Live demo: https://jsfiddle.net/BlackLabel/hsrxtjaw/
API Reference: https://api.highcharts.com/highcharts/series.column.pointRange
I have two circle pie charts, they're looking good but I need to change the background color of the inner core:
$(document).ready(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
//backgroundColor: 'rgba(255, 255, 255, 0.0)',
//backgroundColor: 'rgba(255, 255, 255, 0.0)',
backgroundColor: '#FCFFC5',
margin: [0, 0, 0, 0],
spacingTop: 23,
spacingBottom: 23,
spacingLeft: 23,
spacingRight: 23,
plotBorderWidth: 1,
//polar: true,
//type: 'inline'
},
exporting: { enabled: false },
credits: {
enabled: false
},
plotOptions: {
size: '100%',
series: {
states: {
hover: {
enabled: false
}
}
},
pie: {
innerSize: 100,
backgroundColor: '#CCC',
depth: 15,
dataLabels: {
connectorWidth: 0
}
}
},
tooltip: {
enabled: false
//pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
title: {
text: '<div style="background-color:#2cb5e1;">Today WalkIn<br>67<br>Average wait time<br> 02:00</div>',
align: 'center',
verticalAlign: 'middle',
y: 5,
style: {
color: '#000',
fontWeight: 'bold',
fontSize: '28px',
}
},
legend: {
layout: "vertical",
align: "right",
verticalAlign: "middle",
},
series: { states: { hover: { enabled: false } } },
series: [{
type: 'pie',
dataLabels: false,
shadow: false,
data: [{
name: '',
y: 7,
color: '#fc525a',
}, {
name: '',
y: 5,
color: '#2cb5e1',
}, {
name: '',
y: 18,
color: '#fc8b4d',
}],
innerSize: '65%'
},
{
type: 'pie',
data: [{
name: '',
y: 7,
color: '#fc525a',
}, {
name: '',
y: 5,
color: '#2cb5e1',
}, {
name: '',
y: 18,
color: '#fc8b4d',
}],
innerSize: '80%'
}]
});
});
yellow color background comes out of the two pie chart circles; instead, I wanted to display the color only where text has been placed
Screenshot
You need to draw a custom shape, for example:
chart: {
...,
events: {
load: function() {
var x = this.chartWidth / 2,
y = this.chartHeight / 2,
r = x > y ? y : x;
this.renderer
.circle(x, y, 0.65 * r)
.attr('fill', '#F0F')
.add()
}
}
}
Live demo: http://jsfiddle.net/BlackLabel/apmvgnb4/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#circle
This is a follow-up issue I'm having to this answered problem. I needed help with keeping series grouped together, but spaced apart between categories. I've added drilldown to the chart, and there is an issue with the datalabels when drilling down - they don't center over the columns anymore. The more you drill up and down, the more off they become. I've figured out the reason has to do with resetting the category names, although I have no idea why or what to do about it. But in the drilldown event, if you comment out where the categories are getting reset, the datalabels are centered again.
Here's a fiddle to show what I mean -- any suggestions?
var redrawEnabled = true;
var refChart = new Highcharts.chart('ctReferralsDetail', {
chart: {
backgroundColor: 'whiteSmoke',
type: 'column',
width: 800,
events: {
drilldown: function() {
refChart.xAxis[0].setCategories(["Ballard", "Butler", "Central", "Doss", "Iroquois", "Male", "Pleasure Ridge"]);
refChart.xAxis[0].update({
max: categoriesAA.length - 1
}, true);
this.update({
scrollbar: {
enabled: true,
}
}, false);
redraw(this);
},
drillupall: function() {
this.update({
scrollbar: {
enabled: false
}
}, false);
redraw(this);
},
render: function() {
redraw(this);
},
}
},
title: {
text: "# Referrals"
},
subtitle: {
text: 'subTitle'
},
xAxis: {
categories: ['Elementary 1', 'Elementary 2', 'Elementary 3', 'Middle', 'High'],
min: 0,
max: 4,
},
yAxis: [{
title: {
useHtml: true,
text: '<strong># Referrals</strong>'
}
}],
tooltip: {
shared: true,
},
plotOptions: {
column: {
borderRadius: 5,
dataLabels: {
enabled: true,
allowOverlap: true
},
grouping: false,
pointWidth: 45
}
},
series: [{
name: "2017-18",
data: [{
drilldown: 'py1',
y: 5513
}, {
drilldown: 'py2',
y: 5403
}, {
drilldown: 'py3',
y: 3132
}, {
drilldown: 'py4',
y: 12385
}, {
drilldown: 'py5',
y: 22679
}]
}, {
name: "2018-19",
data: [{
drilldown: 'cy1',
y: 5738
}, {
drilldown: 'cy2',
y: 4397
}, {
drilldown: 'cy3',
y: 3508
}, {
drilldown: 'cy4',
y: 10811
}, {
drilldown: 'cy5',
y: 22743
}]
}],
drilldown: {
allowPointDrilldown: false,
series: [{
name: "2017-18",
id: "py1",
data: [93, 41, 410, 84, 76, 120, 11, 525]
}, {
name: "2018-19",
id: "cy1",
data: [84, 48, 423, 78, 76, 123, 19, 502]
}]
}
})
function redraw(parm) {
var series = parm.series;
if (redrawEnabled) {
if (parm.chartWidth > 600) {
if (parm.options.plotOptions.column.grouping) {
redrawEnabled = false;
parm.update({
plotOptions: {
column: {
grouping: false
}
}
});
redrawEnabled = true;
}
series.forEach(function(s, i) {
s.points.forEach(function(p) {
if (i === 0) {
p.graphic.attr({
translateX: 25
});
p.dataLabel.attr({
translateX: p.dataLabel.translateX + 25
});
} else {
p.graphic.attr({
translateX: -25
});
p.dataLabel.attr({
translateX: p.dataLabel.translateX - 25
});
}
});
});
} else {
if (!parm.options.plotOptions.column.grouping) {
redrawEnabled = false;
this.update({
plotOptions: {
column: {
grouping: true
}
}
});
redrawEnabled = true;
}
}
}
}
In my opinion, you don't need your own function to position the columns as you did. The easiest solution is to remove the pointWidth and then set appropriate pointPadding and groupPadding to create greater space between categories. Then drilldown works as expected. Check demo I posted you below.
Code:
var refChart = new Highcharts.chart('ctReferralsDetail', {
chart: {
backgroundColor: 'whiteSmoke',
type: 'column',
width: 800
},
title: {
text: "# Referrals"
},
subtitle: {
text: 'subTitle'
},
xAxis: {
categories: ['Elementary 1', 'Elementary 2', 'Elementary 3', 'Middle', 'High'],
min: 0,
max: 4,
},
yAxis: [{
title: {
useHtml: true,
text: '<strong># Referrals</strong>'
}
}],
tooltip: {
shared: true,
},
plotOptions: {
column: {
borderRadius: 5,
dataLabels: {
enabled: true,
allowOverlap: true
},
groupPadding: 0.15,
pointPadding: 0.05
}
},
series: [{
name: "2017-18",
data: [{
drilldown: 'py1',
y: 5513
}, {
drilldown: 'py2',
y: 5403
}, {
drilldown: 'py3',
y: 3132
}, {
drilldown: 'py4',
y: 12385
}, {
drilldown: 'py5',
y: 22679
}]
}, {
name: "2018-19",
data: [{
drilldown: 'cy1',
y: 5738
}, {
drilldown: 'cy2',
y: 4397
}, {
drilldown: 'cy3',
y: 3508
}, {
drilldown: 'cy4',
y: 10811
}, {
drilldown: 'cy5',
y: 22743
}]
}],
drilldown: {
allowPointDrilldown: false,
series: [{
name: "2017-18",
id: "py1",
data: [93, 41, 410, 84, 76, 120, 11, 525]
}, {
name: "2018-19",
id: "cy1",
data: [84, 48, 423, 78, 76, 123, 19, 502]
}]
}
});
Demo:
https://jsfiddle.net/BlackLabel/7ok69jbq/1/
Im trying to create plotbands but does not work correctly.
Here is my fiddle and code.
https://jsfiddle.net/z0h85fku/
Javascript
$(function() {
categories = ["09/07/2016 00:00", "09/07/2016 00:01", "09/07/2016 00:02", "09/07/2016 00:03", "09/07/2016 00:04"]
rate_1 = [0.8, 0.54, 0.6, 0.3, 0.4]
rate_2 = [0.33, 0.16, 0.33, 0.3, 0.38]
rate_3 = [0.03, 0.04, 0.05, 0.03, 0.01]
var addCallout = function(chart) {
$('.callout').remove();
var xAxis = chart.xAxis[0],
yAxis = chart.yAxis[0],
series = chart.series[0],
point = series.data[0];
console.log('xAxis == ', xAxis)
console.log('yAxis == ', yAxis.toPixels)
console.log('series == ', series)
console.log('point == ', point)
console.log(point.plotY)
console.log(point.plotX)
var a = chart.renderer.label('<div class="callout top">This is the callout text!</div>', point.plotX + chart.plotLeft - 20,
point.plotY + chart.plotTop - 70, 'callout', null, null, true).add();
};
$('#container').highcharts({
chart: {
// type: 'bar',
events: {
load: function() {
addCallout(this);
},
redraw: function() {
addCallout(this);
},
}
},
title: {
text: 'Spikes Graph',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
events: {
load: function() {
// addCallout(this);
},
redraw: function() {
addCallout(this);
},
},
series: [{
turboThreshold: 2000 // to accept point object configuration
}],
xAxis: {
categories: categories,
<!-- tickInterval: 60,-->
plotBands: [{
color: 'orange', // Color value
// from: Date.UTC(09/07/2016 02:00), // Start of the plot band
// Date.UTC(year,month,day,hours,minutes,seconds,millisec)
from: Date.UTC(2016,9,7,0,0),
to: Date.UTC(2016,9,7,4,0)
// to: '09/07/2016 05:00' // End of the plot band
}],
type:'datetime'
},
yAxis: {
title: {
text: 'Error Rate'
},
min: 0,
max: 5,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
labels: {
format: '{value} %'
}
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [
// {turboThreshold: 2000 },
{
name: 'Rate-1',
data: rate_1,
turboThreshold: 2000,
lineWidth: 1,
dataLabels: {
enabled: true,
useHTML: true,
style: {
fontWeight: 'bold'
},
},
}, {
name: 'Rate-2',
data: rate_2,
turboThreshold: 2000,
lineWidth: 1
}, {
name: 'Rate-3',
data: rate_3,
turboThreshold: 2000,
lineWidth: 1
}
]
});
});