score:1
The problem is definitely that you use d3.select('svg')
or d3.select('app-d3-donut')
in your custom component. d3.select is a wrapper around document.querySelector
, which matches the first element it finds.
You need to make sure that this is not the first SVG element as seen from the document
, but the first element as seen from the custom component. That is - you need to make sure that each Angular component can only look at and modify its own inner HTML.
From the source, d3.select
also accepts HTML elements. So you should use Angular's ViewChild to get a the reference to the SVG element, and then pass that reference to d3
.
@Component({
selector: 'app-d3-donut',
template: `
<svg #chartEl></svg>
`
})
class AppD3DonutComponent {
@ViewChild('chartEl') svgElement: ElementRef;
ngAfterViewInit() {
d3.select(this.svgElement.nativeElement).append('g') // etc
}
}
Source: stackoverflow.com
Related Query
- Rendering a d3 chart in two places makes it render twice in the first area?
- Why does the NVD3.js line plus bar chart example render two charts instead of one?
- Why are the first two text labels of my bar chart not shown?
- d3.js Time Scale Chart, Array object values isnt rendering the chart whereas static values render the chart perfectly
- Update the y-axis of a brushed area chart
- area chart with d3 is not rendering on jsp page but working fine with html
- D3 transition from stacked bar to bar chart only works the first time
- Remove outline along the axes in d3.js area chart
- d3js multi-line chart is being drawn off the plot area - is update pattern to the issue?
- Trying to render data d3 crossfilter dc.js BarChart. The chart is drawn, but it's empty
- How to add non linear curve between any two points of area chart in d3.js
- Pie Chart not rendering in dashboard area using D3 v5
- dc.js - Rendering two objects (one chart - renders, one shape - doesn't) together in one group?
- Why doesn't the same group render a correct line chart and corresponding range chart?
- dc.js - Chart not rendering (single row bar chart - horizontal row), with the exception of legend, axes and tick marks/values (which do render)
- D3 area chart filling above the line
- Update the colored area of a line chart
- D3 area chart not rendering end to end
- d3js Grid outside the chart area
- Show the tooltip value inside the "rect" on mouseover in d3 stacked area chart
- Move legend outside the chart area in C3.js
- How to start D3 JS Tree to render in Collapsible Mode when loaded for the first time
- D3.js: Why the bar chart turns around if I add this two statements
- Unable to show the tooltip values for stacked area chart in a single tooltip
- How to fill the area between the x-segments of two lines in d3.js?
- In d3, how do I apply a style to my line chart for both the line and the area under the line?
- Problems in rendering D3.js Area Chart
- The fill in stacked area chart gets reversed d3
- How to render multi line chart with DC.js with the following type of data - JAVASCRIPT (DC.js)
- Color the area formed between Line Chart and Threshold line
More Query from same tag
- How to create an outline for selected edges and vertices in d3.js?
- D3.js Basic Chart Drawing Example not displayed
- How to make all the nodes circle the center node?
- d3.js: data binding with table and chart
- d3.js: axisBottom is appearing at the top instead
- Associative array in JS: what am I seeing in the debugger
- What is the standard way to get the active (running) D3 v3 Transition for a given element?
- How to display javascript variable as text using D3
- why does appending a foreignObject into an SVG break jquery ui's resize?
- D3 scatterplot click to push and splice data and update the DOM behaves erratically
- Choppy transitions: translate multiple paths (and xaxis) concurrently
- D3.js adjust rect to text size: getBBox()?
- D3.js Collapsible Force Layout, collapsed by default
- How to print different path colors depending on values?
- Javascript / Momentjs: Elegant way to find the min and max time from a set of dates?
- D3 fill transition for heatmap not working
- Partition has a blank slice
- How do I save an adjusted d3.js visualization?
- How to get d3 map to refresh with new saved data with javascript
- How to filter elements and hide others?
- 1d array into binary tree
- How to display text on donut chart for mouseover event
- how to select a custom central-meridian in d3?
- Zoomable Treemap with more than two levels, D3plus?
- Control arrowheads dimension on a force-directed layout in d3.js
- Legend in horizontal multi bar chart
- Can I display D3 graphs on .epub?
- D3.js not parsing the JSON string
- How can I parse "2016-07-18 14:49:11,157" in d3?
- d3.js: extract array in object within array