How can I make a pie chart fill 100% of the divit is contained in? The div has a width of 198px and it's height is 152px.
Additionally I would like to have a linear-gradient effect inside each pie slice, can you advise on how to do that?
You can achieve the full height of the pie chart by setting the size attribute in the plotOptions of pie and removing margins, spacing and titles from the chart.
Code
chart: {
margin: [0, 0, 0, 0],
spacingTop: 0,
spacingBottom: 0,
spacingLeft: 0,
spacingRight: 0
},
plotOptions: {
pie: {
size:'100%',
dataLabels: {
enabled: false
}
}
}
Example (updated the fiddle to point to version 2.2.4)
Here is an example demonstrating this.
As to the linear gradients, I don't know if they have been implemented yet, but here is an example showing radial gradients.
Radial gradients are also part of Highcharts 3.0 now, here is an example
Update
Looks like as of Highcharts 3.0, this is not possible anymore due to the chart auto-scaling within the plot area, an excerpt from their documentation:
size: The diameter of the pie relative to the plot area. Can be a percentage or pixel value. Pixel values are given as integers. The default behaviour (as of 3.0) is to scale to the plot area and give room for data labels within the plot area. As a consequence, the size of the pie may vary when points are updated and data labels more around. In that case it is best to set a fixed value, for example "75%". Defaults to .
in my opinion this should not be the case since dataLabels are disabled. should probably be logged as a bug
Update (Aug 2014)
As per Torstein's comment, this is indeed still possible. slicedOffset needs to be set to 0 in addition to the margins begin set. (example)
$(function () {
$('#container').highcharts({
title: null,
chart: {
type: 'pie',
margin: 0
},
plotOptions: {
pie: {
slicedOffset: 0,
size: '100%',
dataLabels: {
enabled: false
}
}
},
series: [{
data: [
['Firefox', 44.2],
['IE7', 26.6],
['IE6', 20],
['Chrome', 3.1],
['Other', 5.4]
]
}]
});
});
#container {
outline: 1px solid red;
padding: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px; width: 500"></div>
my solutions; (for legend position margin-top error..)
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie',
height:'100%' // added...
},
plotOptions: {
pie: {
size:'100%',
height: '100%',
dataLabels: {
enabled: false
}
}
}
Related
This is the JSFiddle for demonstration.
In the two bars shown in the above JSFiddle, the respective top and the bottom side of the two bars are not black, but grey, since that is the color of the chart border/border of plot area. Would it be possible to make the two bars to be "on top" of the chart border (so that all their sides are black)? I have tried with zIndex in "series". But that does not work.
These are the most relevant javascript code:
Highcharts.chart('container', {
chart: {
type: 'column',
borderWidth: 1,
plotBorderWidth: 1,
marginBottom: 100
},
plotOptions: {
series: {
borderColor: 'black',
animation: false
},
},
xAxis: {
categories: ['1', '2']
},
yAxis: {
tickInterval: 10,
min: -50,
max: 50
},
series: [{
data: [50, -50],
zIndex: 300
}]
});
To achieve this effect, you can set series.column.clip: false.
Disabling this option allows series rendering over plotArea borders.
series: [{
clip: false,
data: [50, -50]
}]
Live demo:
https://jsfiddle.net/BlackLabel/2kyc4dbu/
API reference:
https://api.highcharts.com/highcharts/series.column.clip
When the window size shrinks, the width of the pie is updated, but the height of the whole canvas is not updated, which leads to much space above and below the pie. How can I make sure the graph doesn't take up more space than needed after resize?
Demo: http://jsfiddle.net/remisture/xV8PM/167/
Thanks
$(function() {
$('#container').highcharts({
title: null,
marginLeft: 0,
marginRight: 0,
spacingLeft: 0,
spacingRight: 0,
chart: {
type: 'pie'
},
plotOptions: {
pie: {
size: '100%',
dataLabels: {
enabled: false
},
states: {
hover: {
enabled: false
}
}
}
},
series: [{
data: [
['Firefox', 44.2],
['IE7', 26.6],
['IE6', 20],
['Chrome', 3.1],
['Other', 5.4]
]
}]
});
});
#container {
outline: 1px solid red;
padding: 0;
height: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
Place your container inside a wrapper <div>, set your container width to 100% and then you will have to redraw your chart whenever the window resize event occurs,
Here is a working DEMO: http://jsfiddle.net/xV8PM/172/
Hope this helps!
I need to set a gradient background color to full height of column in Highcharts. Like on the image below. How can I do it? Help me, please.
here an example of what I need
Make another series which has points equaled yAxis maximum value. You can use pattern-fill plugin and set the pattern to a specific column.
$('#container').highcharts({
chart: {
type: 'column'
},
yAxis: {
min: 0,
max: 100
},
plotOptions: {
series: {
pointPadding: 0
}
},
series: [{
enableMouseTracking: false,
showInLegend: false,
grouping: false,
color: 'url(#highcharts-default-pattern-1)',
data: [100, 100]
}, {
data: [20, 50]
}, {
data: [40, 30]
}]
});
You can read more about modifying/creating patterns here - http://www.highcharts.com/docs/chart-design-and-style/gradients-shadows-and-patterns
Live example and output
http://jsfiddle.net/rgs9uv39/
Go here and import your image: http://www.colorzilla.com/gradient-editor/ and after get your css properties.
If you need the element to be full height use:
.yourClass {
height: 100vh;
}
Here I am getting gradient color at top of the chart area by reversing y-Axis. check the image below .
yAxis: {
reversed: true,
showFirstLabel: false,
showLastLabel: true
}
I don't want to reverse the y-Axis, if i am reversing the y-Axis my chart also reversed. I want the gradient color which is in top of the chart line without using this Reversed Y-axis. Suggest me to if any other options in highcharts.
Could any one help me to solve this.
I am working live random data. In this case only the area traveled by the data should get the gradient color , empty space other than the data in chat shouldn't get gradient color.
As per #DaMaxContent answer , the output will act like below image.
I don't want that gradient which filled in other area of the chart data. Could you please help me to resolve this.
The break down:
You can use gridZindex and backgroundColor/fillColor properties to
produce the desired effect. Only issue is that the grid has to be
displayed over graph. Here is the solution: DEMO
Here is the code behind it:
chart: {
type: 'area',
backgroundColor: { //<<--that is what you are using as fill color
linearGradient : {
x1: 0,
y1: 1,
x2: 0,
y2: 0
},
stops : [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
}
},
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
yAxis: {
reversed: false,
showFirstLabel: false,
showLastLabel: true,
gridZIndex: 1000 //<<--grid Z index is used to display grid lines over the graph instead of under it
},
series: [{
name: 'AAPL Stock Price',
data: data,
threshold: null,
fillColor : "#fff", //<<--fill color under the line to simulate effect
zIndex: 1000,
tooltip: {
valueDecimals: 2
}
}]
If you wish to get rid of the marginal color areas, you can get rid off the graphs margin with chart: { [... ,] margin: 0 [, ...] } and then use the container's padding as the graph margin.
more info:
highcharts styling guides:
http://www.highcharts.com/docs/chart-design-and-style/design-and-style
grid Z index:
http://www.java2s.com/Tutorials/highcharts/Example/Axis/Set_grid_line_z_index.htm
background color:
Changing HighCharts background color?
(alternative to bg color) plot background color (bg color of main plot only)
http://api.highcharts.com/highcharts#chart.plotBackgroundColor
Is it possible to add a circle around a pie chart in highcharts?
I know I can do it with an absolute positioned div just over the size of the chart, with a negative zIndex, but it doesn't look entirely right since the graph is drawn with SVG (notice the slight offset on the attached image where I've tried that approach
Thank you!
You could use a shadow with a 0 offset.
http://jsfiddle.net/blaird/RgdJ3/
$(function () {
$('#container').highcharts({
chart: {
type: 'pie'
},
plotOptions: {
pie: {
shadow: {
color: 'black',
offsetX : 0,
offsetY: 0,
opacity: 1,
width: 3
}
}
},
series: [{
data: [
['Firefox', 44.2],
['IE7', 26.6],
['IE6', 20],
['Chrome', 3.1],
['Other', 5.4]
]
}]
});
});