logo
down
shadow

Overlapping legend d3.js


Overlapping legend d3.js

By : José Vera
Date : December 01 2020, 05:00 PM
Hope this helps You will have to update the translate y attribute of groups instead of the paths. And also there is no need for extra calculations for y attributes of texts and paths then.
code :
.attr("transform", function(d, i) {
        return "translate(" + (w + 150) + "," + (30+i*40) + ")";
 });
var w=40; //Sample chart width
 var color = d3.scale.category20c();
var svg = d3.select("body").append("svg").attr({ height: 500, width: 400 });

var legendname = ["Yes", "No"];
var legend = svg.selectAll(".legend")
  .data(legendname)
  .enter().append("g")
  .attr("class", "legend")
  .attr("transform", function(d, i) {
    return "translate(" + (w + 150) + "," + (30+i*40) + ")";
  });

legend.append("path")
  .attr("d", d3.svg.symbol().type("triangle-up").size(128))
  .style('fill', function(d,i) {
    return color(i);
  });

legend.append("text")
   .attr("dx",10)
   .attr("dy",".4em")
  .text(function(d) {
    return d;
  })
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>


Share : facebook icon twitter icon
ggplot2: Legend overlapping the plot area - is it possible to manually adjust legend position?

ggplot2: Legend overlapping the plot area - is it possible to manually adjust legend position?


By : Kevin
Date : March 29 2020, 07:55 AM
I wish this help you In my environment, the legend does not overlap the plot area at all, but anyway what is overlapping is the background of the legend, so you can remove it by:
code :
ggplot(carrots,aes(y=Yield,x=Field,fill=Breed)) +
 geom_bar() +
 opts(legend.direction = "horizontal",
    legend.position = "top",
        legend.background = theme_blank()) + # this does hack
 labs(fill="")
Androidplot legend overlapping

Androidplot legend overlapping


By : Carlos Ernesto
Date : March 29 2020, 07:55 AM
it fixes the issue What can I do to fix the legend overlapping in androidplot? , You can use this to enlarge the legend:
code :
myPlot.getLegendWidget().setSize(new SizeMetrics(15, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
myPlot.position(
        myPlot.getLegendWidget(),
            0,
            XLayoutStyle.ABSOLUTE_FROM_RIGHT,
            0,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
            AnchorPosition.RIGHT_BOTTOM);
myPlot.position(myPlot.getDomainLabelWidget(),                     
            0,                                    
            XLayoutStyle.ABSOLUTE_FROM_LEFT,       
            15,                                     
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM,     
            AnchorPosition.LEFT_BOTTOM);
Matlab: flip legend order and legend overlapping plots after saving

Matlab: flip legend order and legend overlapping plots after saving


By : Ricardo Mawcinitt
Date : March 29 2020, 07:55 AM
To fix the issue you can do The reason for which the code provided in the answer to reverse ordering of legend colors in matlab bar plot does not work in your case is because in that case (plot of a bar chart) the object in the legend are patches while in your plot they are lines.
The FaceColor only applies to patches and not to lines.
code :
p_h=get(gca,'children')
    'NorthOutside'       outside plot box near top
    'SouthOutside'       outside bottom
    'EastOutside'        outside right
    'WestOutside'        outside left
    'NorthEastOutside'   outside top right (default for 3-D plots)
    'NorthWestOutside'   outside top left
    'SouthEastOutside'   outside bottom right
    'SouthWestOutside'   outside bottom left
figure
% Initial plot
h_p=plot(0:.1:2*pi,bsxfun(@plus,sin([0:.1:2*pi]),[3:3:30]'),'linewidth',3)
% Initial legend
[h_leg,b]=legend(cellstr(strcat(repmat('sin(x)+',10,1),num2str([3:3:30]'))))
%
% YOUR CODE TO GENERATE NTHE NEW COLORS
%
map = colormap; % current colormap
n = size(b,1);
z = linspace(size(map,1),1,n/3); % there is 1 text and 2 line elements for every data series, so I divide by 3
z = round(z); %otherwise matlab gets angry that indices must be real integers or logicals
MAP = map(z(:),:); % gets elements specified by linspace from colormap
%
% Reverse the legend strings
%
rev_str=flipud(get(b(1:10),'string'))
%
% Get the handles of the lines in the legend
%
b1=b(11:2:30)
%
% Revere the string in the legend
% and update the color of the lne in the plot using the colors defined in
% MAP
%
p_h=get(gca,'children')
for i=1:10
   set(b(i),'string',rev_str{i})
   set(p_h(i),'color',MAP(i,:),'linewidth',3)
end
%
% Reverse the color of the lines in the legend
for i=1:10
   set(b1(i),'color',MAP(i,:),'linewidth',3)
end
%
% Move the legend outside the axes
%
set(h_leg,'location','NorthEastOutside')
d3 chart legend overlapping

d3 chart legend overlapping


By : Jihad MJR
Date : March 29 2020, 07:55 AM
it helps some times I personally always prefer to wrap legends into g component, and translate it based it's content size .
That way is more space saving & readable
code :
var startX = 30;

legends.each(function(d, i, arr) {
  var wrapper = d3.select(this);  //this is g
  var text = wrapper.select('text');
  var bbox = text.node().getBBox();
  wrapper.attr('transform', 'translate(' + startX + ')');
  startX += bbox.width + 35;
})
Overlapping legend in r plot

Overlapping legend in r plot


By : CodeLyokoXtEAM
Date : March 29 2020, 07:55 AM
this will help You should be reading the manual page for legend - ?legend: You have full control over every aspect of of the placement and font size. First, you do not have room for the legend below the x-axis unless you remove the x-axis label or increase the margin at the bottom (?par, argument mar=). The inset= argument in legend adjusts the position so something like inset=c(0, -.15) will put it below the axis, but you will may need to adjust the -.15 up or down. You also need to include xpd=TRUE so that R knows it is all right to put the legend in the margin below the plot. Finally, cex= controls the expansion of the text with 1 being the default:
code :
plot(NA, xlim=c(0, 1), ylim=c(0, 1), xlab="")
legend("bottom", "A very long legend under the plot",
    xpd=TRUE, inset=c(0, -.15), cex=.8)
Related Posts Related Posts :
  • CRM 2013 Limit the date field
  • fancybox - changing close button color
  • Ember-notify giving error can't read property "Service" of undefined
  • Passport-init.js authentication is not working in nodejs
  • Branch.io Cordova API - init() fails on Android Device
  • appending HTML codes to an elements using js
  • Css animation to extend button text on hover
  • I want to restrict HTML input autocomplete to 3 letter minimum
  • tinyMCE editor not updating on the fly
  • typescript kendo-ui call method from string
  • HttpCompileException was unhandled by user code (when i am adding c# code in script)
  • Send form data as array of objects to controller in asp.net mvc
  • Javascript, multi file modules and Require.Js
  • how to render a complete new template and leave the application template in ember
  • Hover unrelated divs
  • Permute string until it matches some input?
  • How to fire JQuery change event when input value changed programmatically?
  • AJAX: POST data to a different url
  • checkbox column in jquery datatable
  • Document.evaluate for documents without namespaceURI crashes Microsoft Edge
  • Bootstrap Menu with "More" option Responsive issue
  • Standard inputs not being added to Angularjs Form $Scope
  • Express promise throw error
  • onclick and get in jquery
  • How to get the country code from Google Places API
  • Passing parameters url in Select2
  • Is there any frame work for Marklogic to write javascript code?
  • How to implement a boostrap template over bootstrap-sass gem
  • Why fixed div comes out when horizontally scrolled?
  • How to limit scope of a function in javascript/ jquery
  • Apply transition to div
  • Javascript game help - counting with dice
  • How to hide a div from angular controller
  • Can Promise load multi urls in order?
  • How enable Hover event for bootstrap menus?
  • D3 scale.invert() isn't returning date for x
  • Parsing object to array using underscore js or lodash
  • ES6 with React and Browserify
  • AngularJS Factory return type undefined
  • javascript follow html input fields
  • how to declare a double array in javascript for this particular UI
  • Jquery : find length of mixed list
  • Returning the array before the function is complete & Angular JS
  • Javascript set value of class & hidden input in nested divs
  • Register custom filters with vue.js
  • Add class to input parent
  • Angular controller not talking to view
  • Trouble creating "if then" Javascript statement to change background color of page
  • Socket.IO - Middleware and scoping: how should I access global IO object from external middleware?
  • add class when input is valid in angularjs
  • Positioning multiple div elements
  • Checkbox clicking works, deselecting checkbox not working Javascript
  • Adding ajax jQuery File upload
  • Creating a dynamic array within a dynamic array in JQuery
  • Multiple File Upload actions for a single File Input PHP/JS
  • Want to move an added element to a different part of the DOM
  • Why can't I get Angularjs to work?
  • Minimizing browser window in Firefox & Chrome adds white space to right of page
  • I need to insert the date and time of employee stamp in and out into mysql database
  • Making css auto slider
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co