MathieuLuyten
MathieuLuyten

Reputation: 95

Can't display axis to my rickshaw chart

I'm trying to display x- and y-axis to my charts. I'm using JSON for the data.

This is my following code :

new Rickshaw.Graph.Ajax( {

  element: document.getElementById("chart"),
  width: 580,
  height: 300,
  renderer: 'line',
  dataURL: 'dataoutevo.json',
  onData: function(d) { 
    return d },
  onComplete: function(transport) {
    var graph = transport.graph;
    var hoverDetail = new Rickshaw.Graph.HoverDetail( {
      graph: graph
    } );

   var shelving = new Rickshaw.Graph.Behavior.Series.Toggle( {
      graph: graph,
      legend: legend
    } );
  },
  series: [
    {
      name: 'ligne1',
      color: '#c05020',
    }, {
      name: 'ligne2',
      color: '#30c020',
    }, {
      name: 'ligne3',
      color: '#6060c0'
    }, {
      name: 'ligne4',
      color: 'red'
    }
  ],
  onComplete: function() {
    var x_axis = new Rickshaw.Graph.Axis.Time({
      graph: graph
    });
    x_axis.graph.update();
  }
} 

);

Can anyone help me and tell me how to do it ? I have numbers as x- and y-datas (not words)

Upvotes: 0

Views: 983

Answers (2)

pramod24
pramod24

Reputation: 1116

new Rickshaw.Graph.Ajax( {
  element: document.getElementById("chart"),
  width: 580,
  height: 300,
  renderer: 'line',
  dataURL: 'dataoutevo.json',
  onData: function(d) { d[0].data[0].y = 80; return d },
    onComplete: function(transport) {
      // important . do not forget
      var graph = transport.graph;

      var detail = new Rickshaw.Graph.HoverDetail({ graph: graph });
      var legend = new Rickshaw.Graph.Legend({graph: graph,element:   document.querySelector('#legend')});

      var xAxis = new Rickshaw.Graph.Axis.Time({graph: graph});
      xAxis.render();

      var yAxis = new Rickshaw.Graph.Axis.Y({graph: graph});
      yAxis.render();

      var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
        graph: graph,
        legend: legend
      });

      var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
        graph: graph,
        legend: legend
      });
      var order = new Rickshaw.Graph.Behavior.Series.Order({
        graph: graph,
        legend: legend
      });
   },
   series: [
     {
       name: 'ligne1',
       color: '#c05020',
     }, {
       name: 'ligne2',
       color: '#30c020',
     }, {
       name: 'ligne3',
       color: '#6060c0'
     }, {
       name: 'ligne4',
       color: 'red'
     }
   ],
});

Upvotes: 2

flaneur
flaneur

Reputation: 66

Changing Rickshaw.Graph.Axis.Time to Rickshaw.Graph.Axis.X worked for me in a very similar situation. BTW your example code shows two definitions of onComplete, which I assume isn't intended?

Upvotes: 0

Related Questions