HARSHAD557
HARSHAD557

Reputation: 41

Dual Y-Axis in Google Charts With Custom step on both dual y axis

I am facing problem with amcharts dual y-axis custom step on each axis so shifting to Google Charts. Does Google Charts support dual y-axis with minimum and maximum with custom step on each axis?

Image is attached for reference:

Amcharts Dual Y-Axis Image

Upvotes: 0

Views: 462

Answers (1)

WhiteHat
WhiteHat

Reputation: 61222

to set dual y-axis, change the targetAxisIndex of one of the series...

  series: {
    1: {
      targetAxisIndex: 1
    }
  },

to set min and max, use viewWindow
and for step, must provide own ticks
for each vAxes

  vAxes: {
    0: {
      viewWindow: {
        min: 0,
        max: 20
      },
      ticks: [0, 5, 10, 15, 20]
    },
    1: {
      viewWindow: {
        min: 120,
        max: 240
      },
      ticks: [120, 160, 200, 240]
    }
  }

see following working snippet...

google.charts.load('current', {
  callback: function () {
    var data = google.visualization.arrayToDataTable([
      ['Label', 'Series 0', 'Series 1'],
      ['a', 10, 150],
      ['b', 12, 180],
      ['c', 14, 210],
      ['d', 16, 240]
    ]);

    var container = document.getElementById('chart_div');
    var chart = new google.visualization.ColumnChart(container);

    chart.draw(data, {
      series: {
        1: {
          targetAxisIndex: 1
        }
      },
      vAxes: {
        0: {
          viewWindow: {
            min: 0,
            max: 20
          },
          ticks: [0, 5, 10, 15, 20]
        },
        1: {
          viewWindow: {
            min: 120,
            max: 240
          },
          ticks: [120, 160, 200, 240]
        }
      }
    });
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

Upvotes: 1

Related Questions