Njax3SmmM2x2a0Zf7Hpd
Njax3SmmM2x2a0Zf7Hpd

Reputation: 1364

Google Charts How to redraw Charts based on its Type been provide as a list?

I am using the following code to make my chart initially. But I want to provide users with set of Charts options list like 'SteppedAreaChart', 'LineChart', 'ColumnChart'

 var barChart = new google.visualization.ChartWrapper({
              'chartType': 'BarChart',
              'containerId': 'chart1',
              'options': {
                'width': '100%',
                'height': 800,
                'chartArea': {top: 0, right: 0, bottom: 0}
              }
            });

I am looking a workaround for 1. ControlWrapper to accept Chart Type 2. Then redraw the below chart accordingly

I tried using statechange no luck still.

barChart.setView({chartType: 'LineChart'});
            barChart.draw();

Upvotes: 0

Views: 1337

Answers (1)

dlaliberte
dlaliberte

Reputation: 3260

There is currently no control that will let you change the chart type of a chart, so your (1) is not possible. However, you should be able to make that change yourself outside of controls. What you tried could potentially work, but I don't see where you specified the data. E.g.

barChart.setDataTable(myTable);

The view_spec that you provide to setView() must contain the entire view, since you are replacing whatever had been specified previously.

Alternatively, you can just call setChartType() to change the type of the chart in the chart wrapper, like this:

barChart.setChartType('LineChart');
barChart.draw()

The docs for ChartWrapper are at: https://google-developers.appspot.com/chart/interactive/docs/reference#chartwrapperobject

Upvotes: 1

Related Questions