kandi X-RAY | D3chart Summary
kandi X-RAY | D3chart Summary
D3chart
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of D3chart
D3chart Key Features
D3chart Examples and Code Snippets
Community Discussions
Trending Discussions on D3chart
QUESTION
So I'm currently writing a Jasmine/Karma Unit Test for an Angular 9 Component.
A short summary how my application works:
I've written a little Funnel
with D3 that displays given data in a funnel-like diagram. Then I've written a FunnelComponent
that contains this Funnel
and also displays some meta information next to the actual diagram.
This is my to be tested Component:
funnel.component.ts
...ANSWER
Answered 2020-Oct-08 at 11:39This does not work, because Funnel is not a provider:
QUESTION
I am trying to build a line chart where I shade between two lines (different colors based on which line is above the other). This works perfectly for linear curving in all cases tested.
However, this needs to work with actual curving (such as curveBasis
, as shown below). This works perfectly if the lines have the exact same x values; but we have cases in which a) one line is longer/shorter than another and/or b) one line may be missing one or more x values in the middle of the line that the other line isn't missing. This is because how a line is drawn between two points changes based on what points come before/after when it's non-linear.
Generally speaking, I understand why this is happening; but I'm having a hard time finding a good solution to make this actually work the way I'd like. I'd love to at least be pointed in the right direction or given some ideas (one idea I considered is listed at the bottom)!
ExamplesHere's how it works with curveLinear
(looks good):
Here's how it looks with curveBasis
if the x values are the same for both lines (looks good):
Here's how it actually looks with curveBasis
if the x values are not the same for both lines (doesn't look good):
Here's the current strategy (note that I refer to the lines as good/bad, where good line on top results in green fill and bad line on top results in red fill) (some stuff removed, like class names, etc to reduce clutter):
...ANSWER
Answered 2020-Sep-25 at 17:48This is not a great solution, but I'm posting because it is a solution (or a partial one at least).
Without getting into too much detail, I noticed that there were actually two possible causes of the issue (one or both could cause the gaps or bleeding):
- The lines don't start and/or end at the same x values.
- The lines don't share a 1 to 1 mapping of x values with actual y values (in other words, at least one of the two lines is "missing" a y value for a corresponding x value that is not missing in the other line).
"Solution"
Note: I've only tested this with curveBasis
--other curving types may not work the same way.
- "Fill in" the missing y values (fixes cause #2 above)--I did this by linear interpolation between closest left/right non-missing points (if the missing value was at the end or beginning of a line, the closest non-missing point value was re-used). Do this in both your normalized and original lines, but don't interpolate between a point in the original line and point that's not in the normalized line--just re-use in this case (see example below).
- "Triplicate" the normalized start/end points (fixes cause #1 above)--I did this by literally cloning the same point two additional times at the x values where the normalized data starts and ends of the line data. Only need to do this in your original (non-normalized) lines--the normalized lines already start/end where they need to. This works for
curveBasis
, because of which points are taken into consideration for the curve--this solution essentially forces a sort of line "end" even if it's in the middle of a line (source for documentation quote below):
[curveBasis] Produces a cubic basis spline using the specified control points. The first and last points are triplicated such that the spline starts at the first point and ends at the last point...
Example
Line 1 (x values):
[3, 4, 5, 7, 8, 9, 10, 11]
original
[3, 4, 5, 6 (null y), 7, 8, 9, 10, 11]
normalized, pre-manipulation
[3, 4, 5, 6 (interpolated y), 7, 8, 9, 10, 11]
normalized, post-manipulation
[3, 3, 3, 4, 5, 6 (interpolated y), 7, 8, 9, 10, 11, 11, 11]
original, post-manipulation
Note that for line 1, we could skip triplicating the start/end points, since they're already the start/end of the original line
Line 2 (x values):
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13]
original
[3, 4, 5, 6, 7, 8, 9, 10, 11 (null y)]
normalized, pre-manipulation
[3, 4, 5, 6, 7, 8, 9, 10, 11 (re-used y from 10)]
normalized, post-manipulation
[1, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11 (re-used y from 10), 11 (re-used y from 10), 11 (re-used y from 10), 13]
original, post-manipulation (note that we do not interpolate between 10 and 13 to get 11, because 13 doesn't exist in the normalized line)
What does it look like?
Not really that great--but, hey, there are no gaps or bleed overs! The arrows point to where we've "triplicated" points to force the curve to "end" there.
Are we going to use this?
Not likely. I'm still searching for a better solution; but this is what I've come up with so far.
QUESTION
I have a React component that renders a D3 bar chart where the bars are clickable. It works as expected until the parent state is updated. The bars update correctly but the click events on the bars are still bound to the previous data. I'm not sure if this is something I'm doing wrong in React or D3 or both. Any help is appreciated.
...ANSWER
Answered 2019-Apr-18 at 06:07You can try the below solution, change the onclick event inside chart to this.chartRef.current.addEventListener(CLICK, ()=>onClick(this.props.data.length);)
, the change the onClick props on chart to onClick={this.handleChartClick}
and then change the handle chart click to handleChartClick = (data) =>{ console.log('data length on click', data);}
I am not sure of the use case on why you want to the pass the data from Chart component via handleChartClick
when it is already available in App class state. You can just use this.state.data.length
in handleChartClick
QUESTION
ANSWER
Answered 2018-Jan-19 at 10:30Try commenting out the margins on the chart :
.margin({top: 30, right: 20, bottom: 50, left: 175})
Hope it helps
QUESTION
ANSWER
Answered 2017-Nov-24 at 10:31i think this is what you are after.
(Admittedly there a prettier ways to do this in ES6)
QUESTION
I have request like this previously:
...ANSWER
Answered 2017-Oct-21 at 11:08First of all, you can create a dictionary
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install D3chart
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page