I am trying to integrate a d3 script in a gwt web application. However, I cannot figure out how to start d3 from JSNI. The d3 code works well individually; I am wondering maybe because the d3 code cannot access the div element?
This is the approach I follow:
+ add 'script' tags to the main header of the html file to indicate d3 libraries
+ Put the following d3 code in the method using JSNI and call the method in onModuleLoad (). d3 code refers to the main div element, which also uses rootPanel.
/*-{ var w = 960, h = 800; var svg = d3.select("#chart2") .append("svg:svg") .attr("width", w) .attr("height", h) .append("svg:g") .attr("transform", "translate(40, 0)"); svg.selectAll("circle") .data([ 32, 57, 112, 293 ]) .enter() .append("circle") .attr("cy", 90) .attr("cx", String) .attr("r", Math.sqrt); }-*/;
I also tried a different approach; I added another div element inside the HTML element in the Java class and tried to access the second div from d3.
In both cases, nothing appears. any idea how this might work?
Ehsan source share