Evgenij Reznik
Evgenij Reznik

Reputation: 18614

Adding 2nd Y Axis

I'm trying to add an additional y axis to the right of my diagram.

As described in this example, I added an additional value axis and positioned it on the right:

{
  "id": "v2",
  "position": "right"
}

But it seems to just be ignored.

This is my entire code:

var chart = AmCharts.makeChart("mydia", {
  "type": "xy",
  "dataProvider": data,
  "valueAxes": [{
    "id": "v1",
    "position": "left"
  }, {
    "id": "v2",
    "position": "right"
  }],
  "graphs": [{
    "balloonText": "x:[[x]] y:[[y]]",
    "xField": "ax",
    "yField": "ay",
  }, {
    "balloonText": "x:[[x]] y:[[y]]",
    "xField": "bx",
    "yField": "by",
  }],
});

Anybody an idea?

Here is a fiddle.

Upvotes: 0

Views: 59

Answers (1)

xorspark
xorspark

Reputation: 16012

You have to assign a graph to the second Y Axis or else they'll all use the first valueAxis. This is done through the yAxis property in the XY chart:

  "graphs": [{
    "balloonText": "x:[[x]] y:[[y]]",
    "bullet": "round",
    "xField": "ax",
    "yField": "ay"
  }, {
    "balloonText": "x:[[x]] y:[[y]]",
    "yAxis": "v2", //needs to be the ID or valueAxis object itself
    "bullet": "round",
    "xField": "bx",
    "yField": "by"
  }],

Note that you also need to have data in the graph that uses the second yAxis or it will not appear at all.

Here's your updated fiddle with some dummy data for the second graph.

Upvotes: 2

Related Questions