Highchart long dataLabels and style width - javascript

If we had long dataLabel in a pie chart and we set the style width to 100px (in order to don't have a mini pie) some dataLabel just disappear, e.g. see the value Others1.
How to solve this?
http://jsfiddle.net/htwh3rdh/4/
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b style="width: 100px; display: block;">{point.name}</b>: {point.percentage:.1f} %',
style: {
width: '100px',
},
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 40],
['Safari veryveryveryvery long label', 8.5],
['Opera veryveryveryvery long label', 6.2],
['Others veryveryveryvery long label', 0.7],
['Safari1 veryveryveryvery long label', 2.5],
['Opera1 veryveryveryvery long label', 3.2],
['Others1 veryveryveryvery long label', 0.6]
]
}]
});
});

In these cases (in my experience) (with long names and small graphics) would be better to use a pie chart with a legend of this type. In this way you don't have problems with the display of names.
JSFIDDLE
$(function () {
$(document).ready(function () {
// Build the chart
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox iuyguiygiuygiuygiuy uygiuygiuyg', 45.0],
['IE', 26.8],
{
name: 'Chrome uygiuygiuyg ',
y: 12.8,
sliced: true,
selected: true
},
['Safariiuyg iuygiuyg', 8.5],
['Opera uiy giu y giuy', 6.2],
['Others iuygiuygiuyg', 0.7]
]
}]
});
});
});

Related

Set Opacity using CSS on pie-chart in Highchart

Currently i am facing a problem that i need to set Opacity manualy on pie-chart using Highchart. The following solution works fine if you know what color you wish to assign to the slice. But if the color is picked from a palette which is generic, there is no way to give the opacity. It always takes 0. For Can anyone help me with this.
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
fillOpacity: 0.5,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true,
color: 'rgba(150,100,50,0.1)'
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
You can set opacity by using attr method:
events: {
load: function() {
var points = this.series[0].points;
points[1].graphic.attr({
opacity: 0.4
})
}
}
Live demo: http://jsfiddle.net/BlackLabel/59mye8kn/
API: https://api.highcharts.com/class-reference/Highcharts.SVGElement#attr

how to create scatter dotted graph in php?

i getting issue create dynamic dotted graph in php data fetch data base y-axis data ploat and x-axis date required but getting issue pls give me some hint or google line
i am using this code but x-axis not display date
$(function () {
$('#container').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Height Versus Weight of 507 Individuals by Gender'
},
subtitle: {
text: 'Source: Heinz 2003'
},
xAxis: {
title: {
enabled: true,
text: 'Height (cm)'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
title: {
text: 'Weight (kg)'
}
},
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: 'Female',
color: 'rgba(223, 83, 83, .5)',
data: [[07/07/2004, 51.6], [07/026/2004, 59.0], [08/01/2004, 49.2], [08/26/2004, 63.0]]
}]
}]
}); });

How can I change the colors of the slices of the pie?

I'm trying to change the colors of the pie chart made in jsfiddle. I've tried changing the color where I add the other series data, but it did not work.
Here is the fiddle: http://jsfiddle.net/jpotLvt7/
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Skittle Pack 20oz'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
},
connectorColor: 'silver'
}
}
},
series: [{
type: 'pie',
name: 'Color %',
data: [
['Red', 45.0],
['Yellow', 26.8],
{
name: 'Green',
y: 12.8,
sliced: true,
selected: true
},
['Orange', 8.5],
['Purple', 6.2],
]
}]
});
});
http://jsfiddle.net/jpotLvt7/1/
Highcharts.setOptions({
colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4']
});
refer to : http://api.highcharts.com/highcharts#colors
in your data array when specifying each pie, use the color parameter:
{
name: 'Green',
y: 12.8,
sliced: true,
selected: true,
color: '#00ff00'
}

alert value on graph hover

Here is the fiddle for pie chart.
Pie Chart JSFiddle
On hovering the slice, it displays slive value.
Can I alert the slive value onhover?
Actually my purpose is displaying another PIE chart for that slice on hover or click event of slice.
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: 1,//null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
});
});
yes you can do that.
in tooltip you have formatter this will allow you to have a javascript method to do your own stuff when a point is hovered on the chart.
formatter: function(){
//your stuff here
}
Here is a working example for you : http://jsfiddle.net/XZvuL/
hope this is what you are looking for.
Try this
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
},
point: {
events: {
mouseOver: function (event) {
var point = this;
alert(this.percentage)
}
}
}
}
},
DEMO
Click Event
point: {
events: {
click: function (event) {
var point = this;
alert(this.percentage)
}
}
}
DEMO

Need to link URL in HighChart

I am working with HighChart Plugin to draw piecharts/Bar Graphs. While clicking the pie-chart parts I want to link other pages or in other words i want to redirect to other page.
Demo Link: http://www.highcharts.com/demo/pie-basic
$(function () {
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
});
});
Fiddle Link: http://jsfiddle.net/aravindkumarit/M8a3X/
They are not passing ID for the Parts so I am not able to write any event for the pie-chart parts.
Add
events:{
click: function (event) {
alert(event.point.name);
// add your redirect code and u can get data using event.point
}
}
in plotOptions.pie
like this
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
},
events:{
click: function (event) {
alert(event.point.name);
// add your redirect code and u can get data using event.point
}
}
}
}
SEE DEMO

Categories