1

现场示例:http ://bl.ocks.org/4747134/a702cf79bf10b1438cc665a2438b3f5cf9ab8bf0

代码:

var raw_series = [{"note": "TEXAS LONGHORN", "date": "2013-01-10T00:00:00", "amount": 110.0, "id": 74, "account_id": 1}, {"note": "GOOGLE *FEO Medi", "date": "2013-01-10T00:00:00", "amount": 22.0, "id": 73, "account_id": 1}, {"note": "Pressbyran 5122", "date": "2013-01-10T00:00:00", "amount": 13.0, "id": 77, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-10T00:00:00", "amount": 106.0, "id": 76, "account_id": 1}, {"note": "H\u00c5R 3000", "date": "2013-01-10T00:00:00", "amount": 345.0, "id": 75, "account_id": 1}, {"note": "Pressbyran 5122", "date": "2013-01-11T00:00:00", "amount": 19.0, "id": 72, "account_id": 1}, {"note": "BIRKA PUNKTEN", "date": "2013-01-11T00:00:00", "amount": 79.0, "id": 71, "account_id": 1}, {"note": "DROPBOX", "date": "2013-01-11T00:00:00", "amount": 67.0, "id": 70, "account_id": 1}, {"note": "KAFFESTUGAN", "date": "2013-01-11T00:00:00", "amount": 165.0, "id": 69, "account_id": 1}, {"note": "BIRKA PUNKTEN", "date": "2013-01-12T00:00:00", "amount": 79.0, "id": 67, "account_id": 1}, {"note": "GOOGLE *Chozabu", "date": "2013-01-13T00:00:00", "amount": 15.0, "id": 63, "account_id": 1}, {"note": "VIDEO RULLEN", "date": "2013-01-13T00:00:00", "amount": 171.0, "id": 66, "account_id": 1}, {"note": "\u00c5SGATAN 2 K\u00d6K &", "date": "2013-01-13T00:00:00", "amount": 224.0, "id": 65, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-13T00:00:00", "amount": 209.0, "id": 64, "account_id": 1}, {"note": "GOOGLE *Camel Ga", "date": "2013-01-13T00:00:00", "amount": 7.0, "id": 62, "account_id": 1}, {"note": "THE RACKSPACE CL", "date": "2013-01-16T00:00:00", "amount": 252.0, "id": 59, "account_id": 1}, {"note": "Pressbyran 8535", "date": "2013-01-16T00:00:00", "amount": 33.0, "id": 61, "account_id": 1}, {"note": "BIRKA PUNKTEN", "date": "2013-01-16T00:00:00", "amount": 79.0, "id": 60, "account_id": 1}, {"note": "KAFFESTUGAN", "date": "2013-01-16T00:00:00", "amount": 75.0, "id": 58, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-18T00:00:00", "amount": 80.0, "id": 56, "account_id": 1}, {"note": "STATION", "date": "2013-01-18T00:00:00", "amount": 89.0, "id": 55, "account_id": 1}, {"note": "FREE SOFTWARE FO", "date": "2013-01-19T00:00:00", "amount": 132.0, "id": 52, "account_id": 1}, {"note": "\u00d6verf\u00f6ring 100/m\u00e5n", "date": "2013-01-19T00:00:00", "amount": 100.0, "id": 53, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-19T00:00:00", "amount": 321.0, "id": 51, "account_id": 1}, {"note": "VIDEO RULLEN", "date": "2013-01-21T00:00:00", "amount": 179.0, "id": 46, "account_id": 1}, {"note": "Automatuttag", "date": "2013-01-21T00:00:00", "amount": 300.0, "id": 49, "account_id": 1}, {"note": "\u00c5SGATAN 2 K\u00d6K &", "date": "2013-01-21T00:00:00", "amount": 26.0, "id": 48, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-21T00:00:00", "amount": 174.0, "id": 47, "account_id": 1}, {"note": "MSFT   *XBOX LIV", "date": "2013-01-22T00:00:00", "amount": 69.0, "id": 45, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-23T00:00:00", "amount": 293.0, "id": 43, "account_id": 1}, {"note": "PIZZERIA CUOCO P", "date": "2013-01-23T00:00:00", "amount": 140.0, "id": 42, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-24T00:00:00", "amount": 283.0, "id": 41, "account_id": 1}, {"note": "HOTELL NORRTULL", "date": "2013-01-25T00:00:00", "amount": 98.0, "id": 38, "account_id": 1}, {"note": "MAT P\u00c5 JOBB", "date": "2013-01-25T00:00:00", "amount": 80.0, "id": 39, "account_id": 1}, {"note": "\u00d6verf\u00f6ring LOVA/peng", "date": "2013-01-26T00:00:00", "amount": 9000.0, "id": 37, "account_id": 1}, {"note": "Pressbyran 5122", "date": "2013-01-26T00:00:00", "amount": 18.0, "id": 33, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-26T00:00:00", "amount": 373.0, "id": 34, "account_id": 1}, {"note": "J\u00c4RNA W\u00c4RDSHUS", "date": "2013-01-26T00:00:00", "amount": 60.0, "id": 35, "account_id": 1}, {"note": "GETSENTRY LLC", "date": "2013-01-26T00:00:00", "amount": 59.0, "id": 36, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-27T00:00:00", "amount": 556.0, "id": 31, "account_id": 1}, {"note": "WWW.NETFLIX.COM", "date": "2013-01-27T00:00:00", "amount": 79.0, "id": 30, "account_id": 1}, {"note": "DIREKTEN GOTTCEN", "date": "2013-01-27T00:00:00", "amount": 175.0, "id": 32, "account_id": 1}, {"note": "\u00c5SGATAN 2 K\u00d6K &", "date": "2013-01-28T00:00:00", "amount": 154.0, "id": 27, "account_id": 1}, {"note": "HYRESG\u00c4STF\u00d6R", "date": "2013-01-28T00:00:00", "amount": 80.0, "id": 26, "account_id": 1}, {"note": "Automatuttag", "date": "2013-01-28T00:00:00", "amount": 800.0, "id": 25, "account_id": 1}, {"note": "REST KINA MUREN", "date": "2013-01-28T00:00:00", "amount": 428.0, "id": 24, "account_id": 1}, {"note": "KOLINGSBORG", "date": "2013-01-28T00:00:00", "amount": 200.0, "id": 23, "account_id": 1}, {"note": "KOLINGSBORG", "date": "2013-01-28T00:00:00", "amount": 105.0, "id": 22, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-01-28T00:00:00", "amount": 199.0, "id": 21, "account_id": 1}, {"note": "SPOTIFY PREMIUM", "date": "2013-01-28T00:00:00", "amount": 99.0, "id": 19, "account_id": 1}, {"note": "7-Eleven 16110 G", "date": "2013-01-28T00:00:00", "amount": 136.0, "id": 20, "account_id": 1}, {"note": "\u00d6verf\u00f6ring Spar, 3k", "date": "2013-01-28T00:00:00", "amount": 3000.0, "id": 29, "account_id": 1}, {"note": "\u00c5SGATAN 2 K\u00d6K &", "date": "2013-01-28T00:00:00", "amount": 235.0, "id": 28, "account_id": 1}, {"note": "FREE SOFTWARE FO", "date": "2013-01-30T00:00:00", "amount": 65.0, "id": 17, "account_id": 1}, {"note": "PAYPAL *SQUAD-KS", "date": "2013-01-30T00:00:00", "amount": 154.0, "id": 18, "account_id": 1}, {"note": "SJ REGIONAL STOC", "date": "2013-01-31T00:00:00", "amount": 56.0, "id": 16, "account_id": 1}, {"note": "CIAO CIAO QUATTR", "date": "2013-02-01T00:00:00", "amount": 220.0, "id": 13, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-02-01T00:00:00", "amount": 50.0, "id": 15, "account_id": 1}, {"note": "APOTEKET DRAKEN", "date": "2013-02-01T00:00:00", "amount": 48.0, "id": 14, "account_id": 1}, {"note": "GRET INDIAN REST", "date": "2013-02-01T00:00:00", "amount": 85.0, "id": 12, "account_id": 1}, {"note": "LINODE.COM", "date": "2013-02-02T00:00:00", "amount": 613.0, "id": 11, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-02-03T00:00:00", "amount": 110.0, "id": 10, "account_id": 1}, {"note": "ICA SUPERMARKET", "date": "2013-02-04T00:00:00", "amount": 196.0, "id": 9, "account_id": 1}, {"note": "VIDEO RULLEN", "date": "2013-02-04T00:00:00", "amount": 169.0, "id": 8, "account_id": 1}, {"note": "OLEARYS 917", "date": "2013-02-06T00:00:00", "amount": 309.0, "id": 4, "account_id": 1}, {"note": "GRET INDIAN REST", "date": "2013-02-06T00:00:00", "amount": 85.0, "id": 6, "account_id": 1}, {"note": "TAXI STOCKHOLM", "date": "2013-02-06T00:00:00", "amount": 875.0, "id": 5, "account_id": 1}, {"note": "BURGER KING ODEN", "date": "2013-02-06T00:00:00", "amount": 89.0, "id": 3, "account_id": 1}, {"note": "\u00c5SGATAN 2 K\u00d6K &", "date": "2013-02-07T00:00:00", "amount": 226.0, "id": 2, "account_id": 1}, {"note": "Loopia AB", "date": "2013-02-07T00:00:00", "amount": 178.0, "id": 1, "account_id": 1}];

var margin = {top: 20, right: 30, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var format = d3.time.format('%Y-%m-%dT%H:%M:%S')

raw_series.forEach(function (d) { d.date = format.parse(d.date); })

var x = d3.time.scale()
        .range([0, width]);

var y = d3.scale.linear()
        .range([height, 0]);

var z = d3.scale.category20c();

var xAxis = d3.svg.axis()
    .scale(x)
    .orient('bottom')
    .ticks(d3.time.days)

var yAxis = d3.svg.axis()
    .scale(y)
    .orient('left');

var stack = d3.layout.stack()
    .offset('zero')
    .values(function (d) { return d.values; })
    .x(function (d) { return d.date; })
    .y(function (d) { return d.amount; });

var nest = d3.nest()
    .key(function (d) { return d.note })
    .key(function (d) { return d.date })

var area = d3.svg.area()
        .interpolate('monotone')
        .x(function (d) { return x(d.date); })
        .y0(function (d) { return y(d.y0); })
        .y1(function (d) { return y(d.y0 + d.y); });

var svg = d3.select('#chart').append('svg')
    .attr('width', width + margin.left + margin.right)
    .attr('height', height + margin.top + margin.bottom)
  .append('g')
    .attr('transform', 'translate(' + margin.left + ', ' + margin.top + ')');

var layers = stack(nest.entries(raw_series));

x.domain(d3.extent(raw_series, function (d) { return d.date; }));
y.domain([0, d3.max(raw_series, function (d) { d.y0 + d.y; })]);

svg.selectAll(".layer")
    .data(layers)

  .enter().append("path")
    .attr("class", "layer")
    .attr("d", function(d) { return area(d.values); })
    .style("fill", function(d, i) { return z(i); });

svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis);

svg.append("g")
    .attr("class", "y axis")
    .call(yAxis);

输出:

<g transform="translate(40, 20)">
  <path class="layer" d="MNaN,NaNLNaN,450Z" style="fill: #3182bd;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #6baed6;"/>
  <path class="layer" d="MNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNLNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNZ" style="fill: #9ecae1;"/>
  <path class="layer" d="MNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNLNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNZ" style="fill: #c6dbef;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #e6550d;"/>
  <path class="layer" d="MNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNLNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNZ" style="fill: #fd8d3c;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #fdae6b;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNZ" style="fill: #fdd0a2;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #31a354;"/>
  <path class="layer" d="MNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNLNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNZ" style="fill: #74c476;"/>
  <path class="layer" d="MNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNLNaN,NaNCNaN,NaN,NaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNSNaN,NaN,NaN,NaNZ" style="fill: #a1d99b;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #c7e9c0;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #756bb1;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #9e9ac8;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #bcbddc;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNZ" style="fill: #dadaeb;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #636363;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNZ" style="fill: #969696;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #bdbdbd;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #d9d9d9;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #3182bd;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #6baed6;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #9ecae1;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #c6dbef;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #e6550d;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #fd8d3c;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #fdae6b;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #fdd0a2;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #31a354;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #74c476;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #a1d99b;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #c7e9c0;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #756bb1;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #9e9ac8;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #bcbddc;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #dadaeb;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #636363;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNZ" style="fill: #969696;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #bdbdbd;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #d9d9d9;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #3182bd;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #6baed6;"/>
  <path class="layer" d="MNaN,NaNLNaN,NaNZ" style="fill: #9ecae1;"/>
  <g class="x axis" transform="translate(0,450)">
    <g class="tick major" style="opacity: 1;" transform="translate(0,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Thu 10
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(31.785714285714285,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Fri 11
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(63.57142857142857,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Sat 12
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(95.35714285714286,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Jan 13
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(127.14285714285714,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Mon 14
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(158.92857142857144,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Tue 15
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(190.71428571428572,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Wed 16
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(222.5,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Thu 17
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(254.28571428571428,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Fri 18
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(286.0714285714286,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Sat 19
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(317.8571428571429,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Jan 20
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(349.6428571428571,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Mon 21
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(381.42857142857144,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Tue 22
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(413.2142857142857,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Wed 23
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(445,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Thu 24
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(476.7857142857143,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Fri 25
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(508.57142857142856,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Sat 26
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(540.3571428571429,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Jan 27
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(572.1428571428572,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Mon 28
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(603.9285714285714,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Tue 29
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(635.7142857142858,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Wed 30
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(667.5,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Thu 31
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(699.2857142857142,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        February
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(731.0714285714287,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Sat 02
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(762.8571428571429,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Feb 03
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(794.6428571428572,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Mon 04
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(826.4285714285714,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Tue 05
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(858.2142857142858,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Wed 06
      </text>
    </g>
    <g class="tick major" style="opacity: 1;" transform="translate(890,0)">
      <line x2="0" y2="6"/>
      <text dy=".71em" style="text-anchor: middle;" x="0" y="9">
        Thu 07
      </text>
    </g>
    <path class="domain" d="M0,6V0H890V6"/>
  </g>
  <g class="y axis">
    <path class="domain" d="M-6,0H0V450H-6"/>
  </g>
</g>

我一直在研究这个特殊的堆积面积图。我对 d3 还很陌生,所以我需要一些关于在哪里放置什么的指针,以便 d3 获得正确的信息。

4

1 回答 1

2

输入数据不正确:

请注意,每个系列的每个系列必须具有相同数量的值,并且每个值必须具有相同的 x 坐标;如果每个系列的数据缺失或 x 坐标不一致,则必须在计算堆叠布局之前重新采样和插值数据。
https://github.com/mbostock/d3/wiki/SVG-Shapes#wiki-area

于 2013-02-09T22:04:10.680 回答