Highcharts Legend: Overlapping Chart on Small Screens - highcharts

I've created an area chart that should be one-size-fits-all for various screen sizes. The issue comes in when viewing the chart on a phone. The legend overlaps the chart.
Here is the current config:
chart: {
backgroundColor: '#EFEFEF',
margin: [50,10,60,50]
},
credits: {
enabled: false
},
title: {
text: 'Engagement Index Score',
style: {
color: '#555555',
fontWeight: 'normal',
fontSize: 13
}
},
legend: {
borderWidth: 0,
symbolPadding: 10,
itemMarginBottom: 10,
itemDistance: 20,
itemStyle: {
color: '#555555',
cursor: 'default'
},
itemHoverStyle: {
color: '#555555'
}
},
yAxis: {
min: 0,
title: {
text: '% of U.S. Workers',
style: {
color: '#555555',
fontWeight: 'normal',
fontSize: 13
},
margin: 15
}
},
xAxis: {
min: 5,
max: 100
},
plotOptions: {
area: {
connectNulls: true
},
scatter: {
color: '#565656',
dashStyle: 'dash',
lineWidth: 2,
zIndex: 100,
events: {
legendItemClick: function () {
return false;
}
},
enableMouseTracking: false,
events: {
legendItemClick: function () {
return false;
}
}
}
},
series: [{
type: 'scatter',
name: ['You!'],
data: [[80,21]],
marker: {
symbol: 'url(img/star.png)'
}
}, {
type: 'scatter',
name: null,
data: [[80,0], [80,20]],
marker: {
enabled: false
},
showInLegend: false
}, {
type: 'area',
name: ['Disengaged'],
data: [[5,0],[10,4],[15,4],[20,3],[25, 3],[30, 7],[35, 7],[40, 9], [45, 9], [49.5, 14]],
color: '#EA2428',
marker: {
enabled: false
}
}, {
type: 'area',
name: ['Under Engaged'],
data: [[49.5, 14], [55,14], [60, 14], [65, 13], [70, 13], [74.5, 18]],
color: '#F79420',
marker: {
enabled: false
}
}, {
type: 'area',
name: ['Moderately Engaged'],
data: [[74.5, 18], [80, 18], [85, 8], [90, 8], [95, 8], [99.5, 20]],
color: '#18AFE6',
marker: {
enabled: false
}
}, {
type: 'area',
name: ['Fully Engaged'],
data: [[99.5, 20], [100, 20]],
color: '#5C2E8F',
marker: {
enabled: false
}
}]
Here is a fiddle with the current config:
http://jsfiddle.net/gabezeck/8Beea/
Adjust the width of the rendered code to see how it would look in mobile.
Does anyone have a good solution? Can the legend grow down instead of up?
Creating a static HTML version of the legend is not an option, nor is a solution that displays all data series in the chart. We need to hide one, as one of them has the sole function of drawing that dotted line that you see.
Thanks for the help!

Remove the Margin, and it will take dynamic Margins, and adjust the Legend's Position by itself, Check this updated Fiddle

Only what comes to my mind is catch resize event or chekcing width and then position legend.

Related

HighCharts - Single legend for two columns in a Stack Column chart

I have four stack in a Stacked Column chart: "One Completed", "One Pending", "Two Completed", "Two Pending".
By default, I have four legends for these stacks.
What I want is to have two legends: "One" and "Two". Is it possible using Highcharts?
Edit:
Added code. Some of text/logic are removed. Most of the styling is what I found on Internet somewhere.
Highcharts.chart('', {
chart: {
type: 'column',
},
title: {
text: '',
},
xAxis: {
categories: c,
labels: {
y: 40
}
},
yAxis: {
min: 0,
title: {
text: ''
},
stackLabels: {
enabled: true,
verticalAlign: 'bottom',
crop: false,
overflow: 'none',
y: 20,
formatter: function () {
return this.stack
},
style: {
fontSize: '9px',
color: (
Highcharts.defaultOptions.title.style &&
Highcharts.defaultOptions.title.style.color
) || 'gray'
}
}
},
credits: {
enabled: false
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: Highcharts.defaultOptions.legend.backgroundColor || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
//custom logic
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true
}
},
series: {
cursor: 'pointer',
events: {
click: function (event) {
//custom click to filter logic
}
}
}
},
series: [{
name: 'One Pending',
data: one_series_pending,
color: '#7cb5ec',
stack: 'Pending'
}, {
name: 'One Completed',
data: one_series_completed,
color: '#7cb5ec',
stack: 'Completed'
}, {
name: 'Two Pending',
data: two_series_pending,
color: '#434348',
stack: 'Pending'
}, {
name: 'Two Completed',
data: two_series_completed,
color: '#434348',
stack: 'Completed'
}]
});
Sample chart:
I want single legend for same color(two stacks)
You can link one series with another and have one legend item for them by using linkedTo property.
series: [{
name: 'One Pending',
data: [9, 5],
color: '#7cb5ec',
stack: 'Pending'
}, {
name: 'One Completed',
data: [6, 2],
color: '#7cb5ec',
stack: 'Completed',
linkedTo: 0
}, {
name: 'Two Pending',
data: [35, 5],
color: '#434348',
stack: 'Pending'
}, {
name: 'Two Completed',
data: [3, 0],
color: '#434348',
stack: 'Completed',
linkedTo: 2
}]
Live demo: http://jsfiddle.net/BlackLabel/eh5m10q9/
API Reference: https://api.highcharts.com/highcharts/series.column.linkedTo

Highchart - how to control gap between series

In Highcharts, how do I control the gaps between categories?
I've highlighted the area I am talking about in blue below:
I want to make my highchart chart gaps look like this powerpoint version on the left below. The bars in PowerPoint go all the way to the end of the plot area, but highcharts have this big gap.
https://jsfiddle.net/15u0r64s/
Highcharts.chart('container', {
chart: {
type: 'bar'
},
title: {
text: 'Historic World Population by Region'
},
subtitle: {
text: 'Source: Wikipedia.org'
},
xAxis: {
categories: ['Total', 'Male', 'Female', 'Other'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' millions'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 80,
floating: true,
borderWidth: 1,
backgroundColor:
Highcharts.defaultOptions.legend.backgroundColor || '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Total',
data: [10, 20, 31, '']
}, {
name: 'Male',
data: [10, 20, 60, 2]
}, {
name: 'Female',
data: [10, 20, 61, '']
}, {
name: 'Other',
data: [10, 20, 65, 4]
}]
});
You need to edit groupPadding and pointPadding properties:
plotOptions: {
bar: {
groupPadding: 0.05,
pointPadding: 0
}
}
Live demo: https://jsfiddle.net/BlackLabel/oqpxmL18/
API Reference:
https://api.highcharts.com/highcharts/series.bar.groupPadding
https://api.highcharts.com/highcharts/series.bar.pointPadding

Labels on the Y axis and grids

I'm trying to plot a chart using highcharts that looks like this. Could somebody please provide a simple example.
I've tried this:
$(function () {
$('#container').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Positioning Today'
},
subtitle: {
text: 'XXX XXX'
},
xAxis: {
title: {
enabled: true,
text: 'Compliance'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
title: {
text: 'Category'
}
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',
borderWidth: 1
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
}
},
series: [{
name: 'Acme',
color: 'rgba(223, 83, 83, .5)',
data: [[3, 4], [3, 5], [4, 2], [3, 2]]
}, {
name: 'Competitive Landscape',
color: 'rgba(119, 152, 191, .5)',
data: [[4, 3], [5, 3], [2, 4], [2, 3]]
}]
});
});
http://jsfiddle.net/u6gbd6bx/3/
However, I'm struggling to get the grid and labels on the Y axis.
To get the categories on the Y axis, you need to specify the categories in the axis properties:
http://api.highcharts.com/highcharts#yAxis.categories
To get the grid, you can specify a width and a color for the gridlines for each axis:
http://api.highcharts.com/highcharts#yAxis.gridLineColor
http://api.highcharts.com/highcharts#yAxis.gridLineWidth
Note that grid lines on a chart are very often a distraction from the data - make them subtle if they are truly necessary.
To line the grid lines up with the categories, you can use the tickmarkPlacement property:
http://api.highcharts.com/highcharts#yAxis.tickmarkPlacement
And lastly, to get your data to line up correctly with your categories, you need to provide the category array index as the y value.
So, if your first category is "Support", you provide an x value of 0 for any data point in the Support category, etc.
Note also, that by default y axis categories run from bottom to top - if you want them to run from top to bottom, you can set reversed: true on your y axis.
Example:
http://jsfiddle.net/jlbriggs/6a5jdvyy/
Check the following example: http://jsfiddle.net/mushigh/qr815f25/2/
<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; max-width: 800px; margin: 0 auto"></div>
$(function() {
$('#container').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Positioning Today'
},
subtitle: {
text: 'XXX XXX'
},
xAxis: {
title: {
enabled: true,
text: 'Compliance'
},
gridLineWidth: 2,
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
title: {
text: 'Category'
},
categories: ['', 'Support', 'Compliance', 'Risk', 'Fast', 'Easy to Get Started'],
},
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',
y: 15
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x} cm, {point.y} kg'
}
}
},
series: [{
name: 'Acme',
color: 'rgba(223, 83, 83, .5)',
data: [
[3, 4],
[3, 5],
[4, 2],
[3, 2]
]
}, {
name: 'Competitive Landscape',
color: 'rgba(119, 152, 191, .5)',
data: [
[4, 3],
[5, 3],
[2, 4],
[2, 3]
]
}]
});
});

Negative Fill color in AreaSpline Graph

I want to fill area color above the spline in area spline chart.
I have tried to set negative fill color but no result.
Can anyone let me know how to fill area color above the spline rather then below?
Any help will be appreciated.
$(function () {
$('#container').highcharts({
chart: {
type: 'areaspline'
},
title: {
text: 'Average fruit consumption during one week'
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 150,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF'
},
xAxis: {
categories: [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
],
plotBands: [{ // visualize the weekend
from: 4.5,
to: 6.5,
color: 'rgba(68, 170, 213, .2)',
}]
},
yAxis: {
title: {
text: 'Fruit units'
}
},
tooltip: {
shared: true,
valueSuffix: ' units'
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'John',
data: [3, 4, 3, 5, 4, 10, 12],
negativeFillColor: '#000000'
}, {
name: 'Jane',
data: [1, 3, 4, 3, 3, 5, 4],
negativeFillColor: '#000000'
}]
});
})
;
Thanks,
M
Well, threshold should work. Just you need to set
endOnTick: false
maxPadding: 0
threshold: max_value_in_data
See: http://jsfiddle.net/3bQne/1076/
Code:
var data = [3, 4, 3, 5, 4, 10, 12];
Array.prototype.max = function() {
return Math.max.apply(null, this);
}
$('#container').highcharts({
chart: {
type: 'areaspline'
},
yAxis: {
endOnTick: false,
maxPadding: 0
},
plotOptions: {
areaspline: {
threshold: data.max(),
}
},
series: [{
data: data,
negativeFillColor: 'rgba(255, 0, 0, 0.5)'
}]
});

Highcharts multiple series and axes types overlapping

I have a problem with a highcharts graph, regarding overlapping of multiple axes.
There are 2 types of series, one type column and one type line. I want the line type to be always above the others and never intersect them.
You may see my problem here:
http://jsfiddle.net/99tC7/
Anticipated thank you for any help provided.
$('#container').highcharts({
title: {
text: 'Title',
x: -20 //center
},
xAxis: {
categories: [ "5.11.13", "6.11.13", "7.11.13", "8.11.13", "9.11.13"],
labels: {
rotation: 270
}
},
yAxis: [{
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
title:{
text: "Number 1"
},
},
{
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
title:{
text: "Number 2"
},
opposite: true,
max:50,
minPadding:5,
}],
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
borderWidth: 0
},
tooltip: {
enabled: false
},
plotOptions: {
line: {
dataLabels: {
enabled: true,
formatter: function() {
return this.y +'%';
}
}
},
column: {
dataLabels: {
enabled: true,
formatter: function() {
return this.y;
}
}
}
},
series: [{
name: 'L1',
type: 'column',
color: '#FF0000',
yAxis: 0,
data: [1, 5, 9, 10, 12]
},
{
name: 'L2',
type: 'column',
color: '#00FF00',
yAxis: 0,
data: [16, 16, 106, 12, 11]
},
{
name: 'L3',
yAxis: 1,
data: [38, 24, 37, 29, 37]
}
]
});
You can try to set correct min/max values in both yAxis like here http://jsfiddle.net/99tC7/1/

Resources