funnel chart labels out side - javascript

i had tried below code using "https://cdn.jsdelivr.net/npm/chartjs-plugin-piechart-outlabels"
but i m unable to get labels outside can anyone please help me out
pieceLabel: {
render: 'label',
fontColor: '#000',
position: 'outside',
segment: true
}
callbacks: {
label: function(tooltipItem, data) {
var label = data.labels[tooltipItem.index];
var datasetLabel = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
return label + ': ' + datasetLabel + '%';
}
}
and i had tried with datalabels also but no use
i need labels outside which shown in screen shot rounded with pencil

Related

Display legend and colorAxis at different positions in Highchart

I want to display legend for a line series at the top and colorAxis for heatmap at the right side in a chart. There is a global option to position the legend but no separate option for each series.
Highcharts Version: v4.3.1
That feature is not yet implemented in Highcharts core, but it should be available soon: https://github.com/highcharts/highcharts/issues/11309
For now you can move colorAxis from the legend to another place on the chart in this way:
(function(H) {
H.wrap(H.ColorAxis.prototype, 'drawLegendSymbol', function(proceed) {
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
this.legendItemWidth = 0;
this.legendItemHeight = 0;
});
}(Highcharts));
Highcharts.chart('container', {
chart: {
marginRight: 80,
events: {
load: function() {
var chart = this,
colorAxis = chart.colorAxis[0].axisParent.element,
mainSVG = chart.container.children[0],
xPos = chart.plotLeft + chart.plotWidth + 10,
yPos = chart.plotTop;
mainSVG.appendChild(colorAxis);
colorAxis.setAttribute(
'transform', 'translate(' + xPos + ', ' + yPos + ')'
)
}
}
},
series: [{
...,
showInLegend: true
}, {
...,
showInLegend: true
}],
colorAxis: {
layout: 'vertical'
}
});
Live demo: http://jsfiddle.net/BlackLabel/0c9fkvwp/
API Reference: https://api.highcharts.com/highcharts/chart.events
Docs: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

Highcharts Polar charts display labels on specific tick quarters

Considering that my data array is always composed of 4 elements as :
var data = [
{"type":"column","name":"My Label 1","y":38.9500000000003,"color":"#7cb342"},
{"type":"column","name":"My Label 2","y":30,"color":"#7cb342"}, {"type":"column","name":"My Label 3","y":51.85,"color":"#fbc02d"}, {"type":"column","name":"My Label 4","y":55.2999999999997,"color":"#fbc02d"}];
I want to know how to set my data names (data.name) each 45 degrees tick interval to keep them well positioned ?
Here is the example:
http://jsfiddle.net/eento/7rupgxde/4/
It's important for me to display only those labels & keep them inside the global highchart container.
Like this?
dataLabels: {
enabled: true,
formatter: function() {
return this.point.name;
}
}
Example:
http://jsfiddle.net/jlbriggs/7rupgxde/5/
You can use renderer to render those labels, for example, create two methods (one to add labels and one to position them):
function renderLabels(chart) {
var alignments = ['right', 'right', 'left', 'left'];
$.each(chart.series[0].points, function(i, point) {
point.myName = chart.renderer.text(point.name, -9999, -9999).attr({
align: alignments[i],
color: 'black'
}).add();
});
}
function positionLabels(chart, anim) {
var positions = [
// top right label
[chart.plotLeft + chart.plotWidth, chart.plotTop],
// bottom right label
[chart.plotLeft + chart.plotWidth, chart.plotTop + chart.plotHeight],
// bottom left label
[chart.plotLeft, chart.plotTop + chart.plotHeight],
// top left label
[chart.plotLeft, chart.plotTop],
]
$.each(chart.series[0].points, function(i, point) {
if (point.myName) {
point.myName[(anim ? 'animate' : 'attr')]({
x: positions[i][0],
y: positions[i][1],
})
}
});
}
Then use those methods in chart.events:
chart: {
polar: true,
renderTo: 'container',
backgroundColor: null,
events: {
load: function() {
renderLabels(this);
positionLabels(this, false);
},
redraw: function() {
positionLabels(this, true);
}
}
},
And working demo: http://jsfiddle.net/7rupgxde/7/

put a text in all categories in Highcharts

took a long time with this same question, then I appreciate too if I can help.
I researched a lot and understand that by this method that I have in my code will not run. then I can make it work, how I can do? I have tried many things. I do not understand how to adapt a render text or so ago all of my series.
I want to set the VALUE to RIGHT of the bar, and the value of the SERIES (in my case bar1, bar2, bar3) that are always at the LEFT of the bar. as it is in the picture.
this is my code:
http://jsfiddle.net/pb1q9wzk/
plotOptions: {
bar: {
dataLabels: {
padding: 0,
allowOverlap: true,
enabled: true,
align: 'left',
color: '#FFFFFF',
inside: true,
crop: false,
overflow: "none",
formatter: function() {
return this.series.name + " " + this.y;
},
style: {
width:100
}
.
.
.
UPDATE
when it is less than 30, so it appears.
when it is less than 30, "bar" and the value must be outside of the bar.
and when the value is 0, I want to be displayed to the right of "bar".
I appreciate the help, very little css and this library. I still can not get used.
You can do it using dataLabels formatter:
http://api.highcharts.com/highcharts#plotOptions.area.dataLabels.formatter
formatter: function() {
var string = this.series.name + ' ';
if (this.y <= 30) {
string += this.y;
}
return string;
},
Here you will have two possible dataLabels strings, depending on your point value.
You can add custom function responsible for adding second dataLabel in your chart, using Renderer.text:
http://api.highcharts.com/highcharts#Renderer.text
var addSecondLabel = function(chart) {
$('.labelText').remove();
var series = chart.series,
dataLabel, barHeight;
Highcharts.each(series, function(ob, j) {
Highcharts.each(ob.data, function(p, i) {
if (p.y > 30) {
barHeight = p.graphic.element.height.animVal.value;
dataLabel = p.dataLabel;
chart.renderer.text(p.y, dataLabel.x + chart.plotLeft + barHeight, dataLabel.y + chart.plotTop + 11).attr({
zIndex: 100
}).addClass('labelText').css({
"color": "contrast",
"fontSize": "11px",
"fontWeight": "bold",
"textShadow": "0 0 6px contrast, 0 0 3px contrast"
}).add();
} else if (p.y > 0) {
barHeight = p.graphic.element.height.animVal.value;
dataLabel = p.dataLabel;
p.dataLabel.translate(dataLabel.x + barHeight, dataLabel.y);
}
});
});
}
Here I am iterating over all points and adding second label if value of my point is bigger than 30. I am using x and y parameters of this point dataLabel, but I need to add chart.plotLeft and chart.plotTop because chart plotArea is not directly at top left corner.
I am adding class to my labels because I will change their position on redraw and I need to delete previous labels to add labels with new positions.
If my point is bigger than 0 but smaller than 30 I am not adding new label. I am just translating old one so it can be on the left side of column.
example:
http://jsfiddle.net/pb1q9wzk/31/
I update the following part
formatter: function() {
return '<div style="position: absolute; left: 40px"> my label this in other line!<div class="row">bar1</div><div class="row">bar2</div><div class="row">bar3</div></div> <img style="height: 30px; width: 30px; margin-top: 10px" src="https://cdn2.iconfinder.com/data/icons/free-3d-printer-icon-set/512/Plastic_model.png"></img>'
}
http://jsfiddle.net/pb1q9wzk/21/
It is kinda messy but I couldn't figure a better way to do it. Hope it helps

How do I hide y2 axis in dygraph?

How do I hide y2 axis (Z axis) in the chart below using drawAxis option in Dygraph? The drawAxis:false option is not working in example snippet below.
I took the following example from http://dygraphs.com/ 's play example and modified to suite my question.
g = new Dygraph(document.getElementById("graph"),
// For possible data formats, see http://dygraphs.com/data.html
// The x-values could also be dates, e.g. "2012/03/15"
"X,Y,Z\n" +
"1,0,3\n" +
"2,2,6\n" +
"3,4,8\n" +
"4,6,9\n" +
"5,8,9\n" +
"6,10,8\n" +
"7,12,6\n" +
"8,14,3\n", {
// options go here. See http://dygraphs.com/options.html
legend: 'always',
animatedZooms: true,
title: 'dygraphs chart template',
series: {
'Z': {
axis: 'y2'
}
},
axes: {
y2: {
drawAxis: false
}
}
});
/*
Relevant CSS classes include:
Labels on the X & Y axes:
.dygraph-axis-label
.dygraph-axis-label-x
.dygraph-axis-label-y
.dygraph-axis-label-y2
Chart labels, see http://dygraphs.com/tests/styled-chart-labels.html
.dygraph-title
.dygraph-xlabel
.dygraph-ylabel
.dygraph-y2label
The legend, see http://dygraphs.com/tests/series-highlight.html
.dygraph-legend
*/
.dygraph-title {
color: gray;
}
<script src="http://dygraphs.com/dygraph-dev.js"></script>
<!-- You may set style: "width: ...; height: ..." to size the chart -->
<div id="graph"></div>

HighCharts Funnel - Set minimum size of each section

First time ever working with JS and HighCharts... But I'll try to formulate a question so it'll make sense!
At the moment I'm working with only 4 sources of data, which is incredibly easy to throw right in to highcharts.
The problem is, the 4 aggregated numbers is... well, not very consistent.
The numbers I have atm is: 349531093, 156777100, 572480, 7 and 0.
The first number and the second covers the whole funnel, which makes the plot very unattractive and hard to visually see the values.
(Yeah, yeah - the labels are brilliant, but I want to be able to visually see each section).
I've been reading through the documentation of the funnel plot, but I cannot find a way to limit the section size in any way.
So I tried to play around a bit with the different kind of limits, like:
minSize - The minimum size for a pie in response to auto margins. The pie will try to shrink to make room for data labels in side the
plot area, but only to this size. (which does exactly what it says,
so I'm not sure why I even tried it...)
size - that ofc just changed the size of the whole chart....
series: {
dataLabels: {
enabled: true,
format: '<b>{point.name}</b> ({point.y:,.0f})',
minSize: '10%',
color: 'black',
softConnector: true
},
neckWidth: '50%',
neckHeight: '50%',
minSize: '20%',
//-- Other available options
height: '200'
// width: pixels or percent
}
You can see my horrible attempt here at it here: JSFiddle thingy
So to the actual question: Is it possible to set an minimum limit for the section in the funnel?
Any suggestions or just a simple: "dude, not possible" is appreciated!
Cheers!
Unfortunately this is not supported (good idea to post this on userVoice!)
However I have created simple example that you can preprocess data and still display proper values: https://jsfiddle.net/69eey/2/
$(function () {
var dataEx = [
['Raw Events', 349531093],
['Filtered/Aggregated Events', 156777100],
['Correlated Events', 2792294],
['Use Case Events', 572480],
['Finalized', 0]
],
len = dataEx.length,
sum = 0,
minHeight = 0.05,
data = [],
i;
for(i = 0; i < len; i++){
sum += dataEx[i][1];
}
for(i = 0; i < len; i++){
var t = dataEx[i],
r = t[1] / sum;
data[i] = {
name: t[0],
y: ( r > minHeight ? t[1] : sum * minHeight ),
label: t[1]
}
}
It is only workaround of course. You also need to use formatter for a tooltip to make sure you will display proper values (like for dataLabels).
I took Paweł Fus's great example and extended it to include the tooltip correction. Just add the snippet below:
tooltip: {
formatter: function() {
return '<b>'+ this.key +
'</b> = <b>'+ Highcharts.numberFormat(this.point.label, 0) +'</b>';
}
},
JSFiddle with a working example:
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/funnel.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="width: 600px; height: 400px; margin: 0 auto"></div>
JavaScript
$(function () {
var dataEx = [
['Raw Events', 349531093],
['Filtered/Aggregated Events', 156777100],
['Correlated Events', 2792294],
['Use Case Events', 572480],
['Finalized', 0]
],
len = dataEx.length,
sum = 0,
minHeight = 0.05,
data = [];
for(var i = 0; i < len; i++){
sum += dataEx[i][1];
}
for(var i = 0; i < len; i++){
var t = dataEx[i],
r = t[1] / sum;
data[i] = {
name: t[0],
y: ( r > minHeight ? t[1] : sum * minHeight ),
label: t[1]
}
}
$('#container').highcharts({
chart: {
type: 'funnel',
marginRight: 100
},
title: {
text: 'SEIM Metrics',
x: -50
},
tooltip: {
//enabled: false
formatter: function() {
return '<b>'+ this.key +
'</b> = <b>'+ Highcharts.numberFormat(this.point.label, 0) +'</b>';
}
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
formatter: function(){
var point = this.point;
console.log(point);
return '<b>' + point.name + '</b> (' + Highcharts.numberFormat(point.label, 0) + ')';
},
minSize: '10%',
color: 'black',
softConnector: true
},
neckWidth: '50%',
neckHeight: '50%',
//-- Other available options
height: '200'
// width: pixels or percent
}
},
legend: {
enabled: false
},
series: [{
name: 'Unique users',
data: data
}]
});
});
You can try normalizing the values first by taking log.
log(349531093)=8.5
log(572480)=5.75

Categories