Home > Enterprise >  d3 v4 schemeBlues undefined property
d3 v4 schemeBlues undefined property

Time:11-09

I was trying to create a color gradient function:

var blues = d3.scaleOrdinal(d3.schemeBlues[9]);

But received errors on the console pointing to that 9, saying:

Uncaught TypeError: Cannot read properties of undefined (reading '9')

I am referencing v4 of the d3: <script src="https://d3js.org/d3.v4.js"></script>. The fact that that color gradient I was trying to use is in v3 makes me doubt if it's an issue with the version. But I also used d3.geoAlbersUsa() in the same script, which does not seem to work in v3.

Exactly why is schemeBlues not working? Is there a way to fix it?

CodePudding user response:

The color schemes are not included in the D3 default bundle in version 4. You must include an additional library:

<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>

However, in latest version of D3 (version 7), it is included by default.

  • Related