score:3
Accepted answer
I took the working code pen, compiled the coffee and got it working inside your directive. Specifically, accessing the groups
property was the problem. There are no groups. Groups are based on the g
sub-element of svg
. This chart is only made up of div
and span
elements, no svg
.
angular.module('myApp', []).
//camel cased directive name
//in your HTML, this will be named as bars-chart
directive('barsChart', function ($parse) {
var directiveDefinitionObject = {
restrict: 'E',
replace: false,
scope: {
data: '=chartData'
},
link: function (scope, element, attrs) {
var chords, h, strings, w;
w = 32;
h = 32;
strings = ['E', 'B', 'G', 'D', 'A', 'E'];
d3.select(element[0]).selectAll('div').data(scope.data).enter().append('div').attr({
'class': 'chord'
}).each(function (chord, c) {
d3.select(this).append('h3').attr({
'class': 'chord-name'
}).text(function (d) {
return d.name;
});
return d3.select(this).append('div').attr({
'class': 'strings'
}).selectAll('div').data(chord.strings).enter().append('div').attr({
'class': 'string'
}).each(function (string, s) {
var _, frets;
d3.select(this).append('strong').attr({
'class': 'string-name'
}).text(function (d, i) {
return strings[s];
});
frets = function () {
var j, results;
results = [];
for (_ = j = 0; j <= 5; _ = ++j) {
if (window.CP.shouldStopExecution(1)) {
break;
}
results.push(false);
}
window.CP.exitedLoop(1);
return results;
} ();
frets[chord.strings[s]] = true;
console.debug(s, frets);
return d3.select(this).append('span').attr({
'class': 'frets'
}).selectAll('span').data(frets).enter().append('span').attr({
'class': 'fret'
}).append('span').attr({
'class': function (fret, f) {
return fret != false ? 'finger' : 'empty';
}
}).html(function (fret, f) {
return fret != false ? f : '—';
});
});
});
}
}
return directiveDefinitionObject;
});
function Ctrl($scope) {
$scope.chords = [{
name: 'C',
strings: [0, 1, 0, 2, 3, null]
}, {
name: 'D',
strings: [2, 3, 2, 0, null, null]
}, {
name: 'E',
strings: [0, 0, 1, 2, 2, 0]
}, {
name: 'F',
strings: [1, 1, 2, 3, 3, 1]
}, {
name: 'G',
strings: [3, 3, 0, null, 2, 3]
}, {
name: 'A',
strings: [0, 2, 2, 2, 0, null]
}, {
name: 'B',
strings: [2, 3, 4, 4, 2, null]
}, {
name: 'C#',
strings: [3, 4, 5, 5, 3, null]
}, {
name: 'Bm',
strings: [2, 2, 4, 4, 2, null]
}, {
name: 'Bb',
strings: [1, 3, 3, 3, 1, null]
}];
}
Source: stackoverflow.com
Related Query
- D3 chart angular directive not rendering
- D3 Bar chart is not rendering in angular 5
- Angular ng-click's inside a dynamically created d3 chart are not working
- area chart with d3 is not rendering on jsp page but working fine with html
- Angular directive async data not binding?
- angular nvd3 duration not affect pie chart
- AngularJS directive not updating D3 circle pack chart
- d3 re rendering chart exit is not a function
- Pie Chart not rendering in dashboard area using D3 v5
- Angular $compile directive not updating DOM object
- Colour not rendering properly Pie Chart d3
- Angular Directive $watch not responding
- d3JS Chart Not Rendering Properly
- D3.horizon Chart not rendering
- 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 v5 bubble chart using pack not rendering
- d3js angular directive for area chart using d3.mouse event for tooltip
- Angular 2 D3 tree is not rendering correctly
- D3 area chart not rendering end to end
- Data mutation in Angular directive for d3 tree-based chart
- d3.js line chart not rendering stocks line chart
- d3 Stacked Bar Chart - Bars not rendering
- Bar Chart Not Rendering As Intended in d3.JS
- D3js not rendering chart properly: Everything shows up as a line
- angular d3 not rendering uniquely with *ngFor
- Chart not rendering
- D3 not rendering simple bar chart in jade
- D3 area chart not rendering right
- D3, VueJS, axes of chart not rendering
- Angular D3 not displaying line chart
More Query from same tag
- How can one draw thumbnails as children in D3 Zoomable Icicle Layout?
- Adjusting circle size text and svg size
- How to make data() key function to work with TypeScript?
- Is it possible to insert an SVG image into an existing SVG element already rendered on the page?
- Transition for grouped bar chart in d3 when updating the data values
- D3- How to display the ticks of a xAxis
- x coordinate value after drag and drop event
- Label names are not displayed from input data in pie transition chart of d3.js
- d3.js function to filter the interactive chart
- Get red color of schemeCategory10
- D3: How to adjust SVG image path elements programmatically?
- D3.js line chart: axis with fixed position
- D3 date format throwing 'd.getFullYear is not a function'
- How to move connecting path/lines in D3 to edges of shape
- How to do wordwrap for chart labels using d3.js
- Remove NaN values from data in D3.js
- .append() to different selection depending on condition?
- D3js drag vs click
- Is there an issue with putting all of my code in the argument for d3.csv()?
- Need to Hide or Remove alternative x-axis values in d3 charts
- Save D3 svg as a high quality image
- D3 transition not working
- D3 force-directed graph adding new nodes causes x & y to be NaN
- Sum an entire (changing) Object using d3
- Javascript: How to show tooltip by hovering mouse over axis lable
- TopoJSON map not rendering properly using D3
- Change tooltips color d3.js
- Using D3 to retrieve a TopoJSON U.S. county from coordinates
- Axis-range-slider alignment
- What is the correct way of writing a binding for D3.js animations?