Comments (6)
Can you post the code you're using with the legend?
from d3-legend.
I am going to close this issue please respond if you want it re-opened.
from d3-legend.
Hi,
I have the same problem
I'm using it within a react app, so the top part of the code is:
var d3=require('d3')
import legend from 'd3-svg-legend'
and the legend:
mainGraph.append('g')
.attr('transform', 'translate(20,20)')
.call(
legend.legendColor()
.shape('path', d3.symbol().type(d3.symbolTriangle).size(150)())
.shapePadding(10)
.scale(colour)
)
from d3-legend.
The exact file that I am trying this in is:
(the entire repository is my react app in total)
Thanks in advance!
from d3-legend.
@raubreywhite
I looked into your project to figure out why this is happening. It's because you're using the ReactFauxDOM element. At the time the legend code is called there are no elements in the DOM yet so when it's looking for the elements bounding box it can't find the element.
I put the following code in your App.js file's componentDidMount and it did display the legend correctly.
d3.selectAll('#root')
.append('svg')
d3.selectAll('svg')
.append('g')
.attr('transform', 'translate(10,10)')
.call(
legendColor()
.shape("path", d3.symbol().type(d3.symbolTriangle).size(150)())
.shapePadding(10)
.scale(d3.scaleOrdinal()
.range([ '#91cf60', '#ffffbf', '#fc8d59' ])
.domain([0, 1, 2]))
)
One option you could use is the components that are using Barometer, wrap that in an SVG with a Barometer class or id:
<svg className="barometer"><Barometer data={this.state.data} brushValues={this.state.brushValues} width={this.state.dimensions.width}/></svg>
Then within your Barometer component you should be able to select that SVG directly since it will be rendered by the parent already.
from d3-legend.
Thank you!
from d3-legend.
Related Issues (20)
- label color remains black in dark mode
- Last threshold's "more than x" label should be "x or more" HOT 2
- Library is not included in webpack bundle HOT 9
- ENH: labelFormat to support numeraljs format HOT 1
- NS_ERROR_FAILURE errors HOT 15
- help wanted: irregular patch legend HOT 5
- Custom Color and Shape? HOT 2
- legend size defaults to 5 when data has length of 1 HOT 2
- Feature Request: Vertical legend text alignment options HOT 6
- cellclick and "#tag"+d.key.replace(/\s+/g, '') HOT 4
- Support for d3.scaleTime() HOT 2
- legend with clamp values HOT 1
- Scrollable Legend HOT 1
- import problems d3 version 5 HOT 5
- Property 'labelWrap' does not exist on type 'LegendColor' HOT 1
- Legend not showing up properly if hidden using jQuery
- Interface LegendColor, issues with cellFilter method, argument type is missing
- labelWrap only wraps white space
- .on functions don't work with d3 v6 HOT 2
- please upgrade to d3 v6 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-legend.