2

I create the online chart from my pivot table.that pivot table is source my chart.but i can't get chart data table in office script

I need to add "chart data table" from office script code

Here is my code. I don't have any idea how to add that data table in chart.

// Insert pivot chart on sheet sheet1
    let chart_1 = sheet1.addChart(ExcelScript.ChartType.columnClustered, newPivotTable.getLayout().getRange());
    // Resize and move chart chart_1
    chart_1.setLeft(543.75);
    chart_1.setTop(24.75);
    chart_1.setWidth(360);
    chart_1.setHeight(216);
    // Resize and move chart chart_1
    chart_1.setLeft(543.75);
    chart_1.setTop(24.75);
    chart_1.setWidth(468);
    chart_1.setHeight(273);
    // Change major gridlines visibility for chart chart_1
    chart_1.getAxes().getValueAxis().getMajorGridlines().setVisible(false);
    // Change minor gridlines visibility for chart chart_1
    chart_1.getAxes().getValueAxis().getMinorGridlines().setVisible(false);
    // Change title text for chart chart_1
    chart_1.getTitle().setText("Active HC");
Skin
  • 9,085
  • 2
  • 13
  • 29

1 Answers1

0

If you're asking about how to create a chart from a data table you can use most of the code you have above. You just have to reference the range of the data table e.g. in a variable. And then use that variable when you add the chart. So you could use your code in your initial post but edit it like so:

      let dataTbl = sheet1.getRange("data_table_range here") //you will need to change the sheet if the dataTable is not located on Sheet1
      let chart_1 = sheet1.addChart(ExcelScript.ChartType.columnClustered, dataTbl); //you will need to change the sheet if you don't want the chart to appear on Sheet1
Brian Gonzalez
  • 1,178
  • 1
  • 3
  • 15