plotly.js legend overlap the graph - plotly.js

Please see example screenshot - I cannot reproduce except on this site, it seems to be some conflict with the css but any ideas what?
Normally, plotly moves the legend at the top if there is not enough horizontal space. However, this example shows that the legend overlaps the graph. Even if I make the legend orientation horizontal, it still overlaps the graph.
Do you have any ideas why it could happen?

Adjusting the legend position in normalized coordinates should help. See also here.
I.e.:
layout = go.Layout(
legend={"x" : 1.2, "y" : 1}
)

Placing the legend outside of the plot works for me:
var layout = {
showlegend: true,
legend: {
x: 1,
}
};

Fixed by a css wizard https://tiki.org/item6567 (Luci):
.js-plotly-plot .plotly .main-svg {overflow: visible}
.js-plotly-plot .plotly .main-svg .legend {transform: translate(640px, 100px)}

Related

How to align legend dynamically on top-center of the chart in c3.js?

I want to put the same legend top center of the chart. Legend items will be dynamic, likes sometimes 2,5 or 9, etc.
So, it should take space dynamically like how it is acting on the bottom.
I tried with inset functionality but it seems this is not looking better like the bottom one.
and there are few more complexity like I want it like a flat, so now if I define step size 3 then maybe, for now, it looks good for 9 items. but when there will be 2 items, it will show as a list!!
Although I solved that problem through the following solution:
// get parent elements
let parentEle = d3.selectAll("#chartID svg");
let childrenEle = parentEle
//Convert selection to selection representing the children
.selectAll(function () { return this.childNodes; })
.filter('g');
// putting legends position on TOP
d3.select(childrenEle._groups[0][2]).attr('transform', 'translate(0, 5)');
you have to keep eye on chart width - height and according to this, you may have to control padding in TOP for the chart.
might be this is not a good solution but it works fine for me :D

Vertical line on Amcharts instead of the grid

How can I set the vertical lines related to the Category Axis which are NOT the grid ?
Watch the pictures to see what I m looking for.
It s not the grid, I don't think it's neither a trend line nor a guide. It s related to the data.
Any help will be deeply appreciated.
(I tryed to use the Editor to find it out... no magical result lol)
Amchart picture
amchart my result
This is how I fixed my problem :
somewhere after "type": "serial",
"gridAboveGraphs": true, // to get the vertical lines above the graph
And I added in "categoryAxis": { ... }
"gridAlpha": 1, // to make the vertical lines appear
"gridColor": "#ffffff", // to set the color of the lines
"gridPosition": "middle", // instead of 'start' to see the lines like I wanted
I wanna thank people who tried to help me.
Best regards.

How can i set the x axis tick interval to be 1 in C3 / d3 js charts?

I'm very new to chart building with c3 and d3. I've done a search, but I can't find an answer - could anyone help? how can I force the x axis to display every tick mark - it is currently displaying every other one. I want the chart to be dynamic, so I don't want to have to hard wire in the tick count (it is pulling data from elsewhere).
I hope I've made sense! Grateful for any suggestions.
You need to adjust culling option:
axis: {
x: {
tick: {
culling: false
}
}
}
See docs.
Also, you can force visibility of first and last tick value with little css hack:
.c3-axis-x g.tick:nth-last-child(2) text,
.c3-axis-x g.tick:nth-child(2) text {
display: block !important;
}

How to increase vertical offset of tooltip position?

I'm using kendo tooltips on a graphic (within an anchor link) which is 24px tall. Accordingly, when the tooltip shows up (default position of bottom), it covers the bottom third of the graphic and so the bottom third of the graphic can't be clicked.
I can do the following:
.k-tooltip {
margin-top: 8px;
}
But the problem with this is that if the tooltip is on a graphic at the bottom of the page, the position will be "top" instead of "bottom" but it'll now be covering about 1/2 the graphic instead of just a third because it's still being pushed down by 8px.
What I'd like is if the position is bottom, then the margin-top is 8px, but if the position is top, the the margin-bottom is 8px.
Thanks for any help you can provide!
Billy McCafferty
Would this one help you?
http://dojo.telerik.com/amoZE/5
var tooltip = $("#demo").kendoTooltip({
filter: "a",
show: function (e) {
var position = e.sender.options.position;
if (position == "bottom") {
e.sender.popup.element.css("margin-top", "10px");
} else if(position == "top") {
e.sender.popup.element.css("margin-bottom", "10px");
}
}
}).data("kendoTooltip");
Thank you for your answer, jarno-lahtinen. It was very helpful!
Two problems came up with it and I would like to document the solutions here:
1. Property Error in Typescript
I am using TS and it gave me the following error:
"Property popup does not exist on type Tooltip" for e.sender.popup. I am not sure if this is due to a newer version of Kendo, or of missing type definitions.
Solution:
you can use this.popup instead.
2. Not working for position: "top"
Unfortunately, the "margin-bottom" has absolutely no effect because the popup is positioned "absolute" using top/left.
Solution:
this.popup.element.css("margin-top", "-10px");
This will shift the popup upwards by 10 pixels

d3 autospace overlapping tick labels

Is there a way in d3 to not draw overlapping tick labels? For example, if I have a bar chart, but the bars are only 5 pixels wide and the labels are 10 pixels wide, I end up with a cluttered mess. I'm currently working on an implementation to only draw the labels when they do not overlap. I can't find any existing way to do that, but wasn't sure if anyone else had dealt with this problem.
There is no way of doing this automatically in D3. You can set the number of ticks or the tick values explicitly (see the documentation), but you'll have to figure out the respective numbers/values yourself. Another option would be to rotate the labels such that there is less chance of them overlapping.
Alternatively, like suggested in the other answer, you could try using a force layout to place the labels. To clarify, you would use the force layout on the labels only -- this is completely independent of the type of chart. I have done this in this example, which is slightly more relevant than the one linked in the other answer.
Note that if you go with the force layout solution, you don't have to animate the position of the labels. You could simply compute the force layout until it converges and then plot the labels.
I've had a similar problem with multiple (sub-)axis, where the last tick overlaps my vertical axis in some situations (depending on the screen width), so I've just wrote a little function that compares the position of the end of the text label with the position of the next axis. This code is very specific to my use case, but could adapted easily to your needs:
var $svg = $('#svg');
// get the last tick of each of my sub-axis
$('.tick-axis').find('.tick:last-of-type').each(function() {
// get position of the end of this text field
var endOfTextField = $(this).offset().left + $(this).find('text').width();
// get the next vertical axis
var $nextAxis = $('line[data-axis="' + $(this).closest('.tick-axis').attr('data-axis') + '"]');
// there is no axis on the very right, so just use the svg width
var positionOfAxis = ($nextAxis.length > 0) ? $nextAxis.offset().left : $svg.offset().left + $svg.width();
// hide the ugly ones!
if (endOfTextField > positionOfAxis) {
$(this).attr('class', 'tick hide');
}
});
The ticks with color: aqua are the hidden ones:

Resources