0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

npmを用いてd3.jsのd3.scale.categoryを使う

Last updated at Posted at 2016-12-23

概要

d3.jsには、あらかじめ10色や20色のカラーマップが用意されており、それらを利用することで簡単に色分けをすることができます。
(参考:d3.jsのcategorical colorsページ
本来は次のように使います。

const c10 = d3.category10()
const c20 = d3.category20()

これをnpmで利用しようとしたら少しハマったので、参考のためのメモです。

使い方

結論としては、npmを用いてこれらを利用するためにはnpmのd3-scaleを使う必要がありました。
そのため、d3-scaleをinstallして、

import * as d3_scale from 'd3-scale'

とimportして、

const c10 = d3_scale.schemeCategory10;
const c20 = d3_scale.schemeCategory20a;

とすれば使うことができました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?