Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
996 views
in Technique[技术] by (71.8m points)

google charts vAxis to the right

I'm using google visualization

var data2 = new google.visualization.DataTable();
        data2.addColumn('string', 'time');
        data2.addColumn('number', 'amount');
        data2.addColumn({ type: 'string', role: 'tooltip' });
        data2.addRows(rows_data);
        var options2 = {
            vAxis: { textPosition: 'none', title: '', textStyle: { fontName: 'arial'} },
            hAxis: { slantedText: false, textStyle: { color: '#E6EFFA' }, gridlines: { color: '#E6EFFA', count: 20} },
            backgroundColor: '#E6EFFA',
            legend: 'none',
            chartArea: { top: 0 },
            colors: ['#435988'],
            chartArea: { width: 800 }
        };
        chart2 = new google.visualization.LineChart(document.getElementById('chart_div_volume'));

I want the vAxis position to be on the right. is it possible ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Short Answer: Yes, but it's tricky.

Long Answer:

You need to set up a multi-axis chart. Basically, you create a dummy axis with no labels or anything to make it look like an axis. Then you configure a secondary axis. You create one set of dummy values (hidden) to put on the first axis, and plot your real data on the second.

Here is an example:

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Year', 'Dummy', 'Sales', 'Expenses'],
    ['2004',  0,   1000,      400],
    ['2005',  null,   1170,      460],
    ['2006',  null,   660,       1120],
    ['2007',  null,   1030,      540]
  ]);

  var options = {
    title: 'Company Performance',
    series: { 0: {targetAxisIndex: 0, visibleInLegend: false, pointSize: 0, lineWidth: 0},
              1: {targetAxisIndex: 1},
              2: {targetAxisIndex: 1}
             },
    vAxes: {
      0: {textPosition: 'none'},
      1: {},
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById('visualization'));
  chart.draw(data, options);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...