3

Very new to Visual force as well as D3. I am facing the same problem while writing a code "D3 is not defined" I have included the java script file as static resource and tried to include the same.

Regards

7

If you start with this page:

<apex:page>
<div id="target"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.js"></script>
<script type="text/javascript">
d3.select('div#target').append('span').text('Hello world').style('font-size', '200px');
</script>
</apex:page>

that takes the D3 Javascript from a standard location, you can start working with D3. You can move to serving the JavaScript from a static resource later - see below.

PS

To move to using the static resource:

  1. Download the d3.zip from http://d3js.org/.
  2. Upload the file d3.zip as a "Cache Control" "public" static resource called "D3Zip".
  3. Replace the external reference in the above code with <apex:includeScript value="{!URLFOR($Resource.D3Zip, 'd3.js')}"/>. (URLFOR allows the content of ZIP format static resources to be extracted on the fly.) The page should now be working again.
  4. When everything is working well change 'd3.js' to 'd3.min.js' so your code is using the smaller, minified version (147k vs 327k).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.