Two datasets one graph

Posted on
  • Hello,
    is it possible to have multiple datasets in one graph? I tried something like this, but they dont share same 0,0 coordinate:

    var data = [1,0,-1,3,8,10,12,10,8,3,1];
    var data2 = [4,5,2,1,1,8,1,2,3,4,7];
    g.clear();
    require("graph").drawBar(g, data, {
      miny: -1,
      axes : true,
      gridx : 1,
      gridy : 5
    });
    g.setColor(1,0,0);
    require("graph").drawLine(g, data2, {
      miny: -1,
      axes : true,
      gridx : 1,
      gridy : 5,
      x: 0,
      y: 1
    });
    

    Thank you!

  • Hi! Yes, it should be fine - if you're doing more than one graph you'll probably just want to hard-code the ranges so that doesn't happen. I notice you're using miny but you probably want to use maxy too, or that will get set up automatically and will change the '0' position.

    Also because gridy==5 you probably want min/max to be a multiple of 5?

    This seems to work for me:

    var data = [1,0,-1,3,8,10,12,10,8,3,1];
    var data2 = [4,5,2,1,1,8,1,2,3,4,7];
    g.clear();
    require("graph").drawBar(g, data, {
      miny: -5, maxy : 15,
      axes : true,
      gridx : 1,
      gridy : 5
    });
    g.setColor(1,0,0);
    require("graph").drawLine(g, data2, {
      miny: -5, maxy : 15,
      axes : true,
      gridx : 1,
      gridy : 5,
    });
    

    Not sure if it's intentional, but specifying x,y in one but not the other would also misalign the graphs.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Two datasets one graph

Posted by Avatar for docerta @docerta

Actions