square / cubism

Cubism.js: A JavaScript library for time series visualization.
https://square.github.com/cubism/
Other
4.94k stars 526 forks source link

Unable to use extent for currency data #64

Open ronakrrb opened 10 years ago

ronakrrb commented 10 years ago
    var context = cubism.context()
      .serverDelay(0)
      .clientDelay(0)
      .step(1e3)
      .size(960);

    function money(name) {
      var value = 0,
          values = [],
          i = 0,
          last;
      return context.metric(function(start, stop, step, callback) {
        $.getJSON("Website Link", function (api_data) {
          start = +start, stop = +stop;
          if (isNaN(last)) last = start;
          while (last < stop) {
            last += step;
            values.push(_.where(api_data,{"code": name})[0].rate);
          }
          callback(null, values = values.slice((start - stop) / step));
        });
      }, name);
    }

        var USD = money("USD"),
            EUR = money("EUR");
            INR = money("INR");

        d3.select(selection).call(function(div) {

          div.append("div")
              .attr("class", "axis")
              .call(context.axis().orient("top"));

          div.selectAll(".horizon")
              .data([USD, EUR, INR])
            .enter().append("div")
              .attr("class", "horizon")
              .call(context.horizon().format(d3.format(".2f")));

          div.append("div")
              .attr("class", "rule")
              .call(context.rule());

        });

        // On mousemove, reposition the chart values to match the rule.
        context.on("focus", function(i) {
          d3.selectAll(".value").style("right", i == null ? null : context.size() - i + "px");
        });

I am using the above code and the entire band for all the three currencies is having green color without the rates' variation. Check the image image

Please help me out.!!! :(

ronakrrb commented 10 years ago

I have figured out a solution. I now just need to have the data explicitly from the metric and do some calculation to set the extent. Can any one help me with getting the data from metric explicitly

Glavin001 commented 9 years ago

My chart data is looking the same (solid, filled in, output). Did you find a solution for this?