How do I hide y2 axis in dygraph? - javascript

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>

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

funnel chart labels out side

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

Can i show table on x-axis as like grouped categories in highcharts - But no grouping

I just want to show table just below the X-axis column charts (respective bars), I know grouping can create table but i don't want grouping to be used. just need table for x-axis values. As shown in below image,
Can i do this using highcharts properties. Only table will be present to x-axis labels.
Is it possible using highcharts lib ?
You can make ticks longer by setting xAxis.tickLength property.
And then, render an additional line in the bottom of the ticks.
function renderBottomLine() {
var chart = this,
axis = chart.xAxis[0],
line = axis.bottomLine,
x1 = chart.plotLeft,
y = chart.plotTop + chart.plotHeight + axis.options.tickLength,
x2 = x1 + chart.plotWidth,
path = [
'M', x1, y,
'L', x2, y
];
if (!line) {
axis.bottomLine = chart.renderer.path(path).attr({
'stroke-width': 1,
stroke: '#ccd6eb'
}).
add();
} else {
line.animate({
d: path
});
}
}
Highcharts.chart('container', {
chart: {
events: {
load: renderBottomLine,
redraw: renderBottomLine
}
},
example: http://jsfiddle.net/xuyyt6nd/

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

Categories