1
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 3 years have passed since last update.

D3.jsのグラフのタイトルにアイコンをつける

Last updated at Posted at 2021-10-09

#はじめに
デザイン上、D3.jsのグラフのタイトルに画像のアイコンを表示させる必要があったので、調べてみたメモ。

#やり方
単にSVGのImageタグをD3の流儀に従って張り付けるだけ。
座標はうまいこと調整しよう。

// グラフタイトルのアイコン
svg.append("image")
   .attr("x", 0)
   .attr("y", 0) 
   .attr("href", "https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image/mdn_logo_only_color.png")
   .attr("height",20)
   .attr("width",20)

// グラフタイトル
svg.append("text")
    .attr("x", 24)
    .attr("y", 12)
    .attr("font-size", "13px")
    .attr("text-anchor", "top")
    .attr("font-weight", 700)
    .text("タイトル");

するとこんな感じで画像がタイトルの横にアイコンっぽく表示される。当たり前っちゃー、当たり前の話だ。

image.png

#参考

1
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
1
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?