1

私は d3 サンプルhttp://bost.ocks.org/mike/nations/に取り組んでいます:

ここに画像の説明を入力

名前とチェックインの詳細を含むサークルのタイトルを追加しようとしています。

以下は、年表示関数の変更されたコードです (コードの残りの部分はほとんど変更されていません,,,):

 // Updates the display to show the specified year.
  function displayYear(year) {
    dot.data(interpolateData(year), key)
    .call(position)
    .sort(order);

    dot.append("title").text(function(d) { return d.name});

    dot.text(function(d) { return d.name + "~"+ d.checkins + d.Checkintimes; });

    label.text(Math.round(year));

      }
// Interpolates the dataset for the given (fractional) year.
  function interpolateData(year) {
    return nations.map(function(d) {
      return {
        name: d.name,
        region: d.region,
        checkins: interpolateValues(d.checkins, year),
        teamsize: interpolateValues(d.teamsize, year),
        Checkintimes: interpolateValues(d.Checkintimes, year)
      };

    });
  }

ただし、同じものがサークルのタイトルとして表示されていません。チェックインの詳細を円に追加したいだけです。

私のjsonファイルには以下が含まれています:

[ {

"name":"Search&Navigator",
"region":"IPScience",
"checkins":[[2000,100],[2001,200],[2002,300],[2003,275],[2004,222],[2005,280],[2006,281],[2007,400],[2008,55],[2009,300]],
"teamsize":[[2000,10],[2001,7],[2002,7],[2003,12],[2004,5],[2005,3],[2006,10],[2007,12],[2008,12],[2009,10]],
"Checkintimes":[[2000,40],[2001,50],[2002,60],[2003,50],[2004,40],[2005,30],[2006,30],[2007,35],[2008,30],[2009,30]]

} ]

4

1 に答える 1

1

変数に要素dotへの参照が含まれていません。title追加する関数を変更して、必要なことを行うだけです。

dot.append("title")
   .text(function(d) { return d.name + "~"+ d.checkins + d.Checkintimes; });
于 2013-11-11T17:25:39.540 に答える