Excel.ChartSeriesBy enum

指定序列是按行还是按列。 在桌面版 Excel 中,“自动”选项将检查源数据形状,以自动猜测数据是按行还是按列。 在Excel web 版中,“auto”将仅默认为“columns”。

注解

[ API 集:ExcelApi 1.1 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-data-source.yaml

await Excel.run(async (context) => {
  // Create a new worksheet called "Sample" and activate it.
  context.workbook.worksheets.getItemOrNullObject("Sample").delete();
  const sheet = context.workbook.worksheets.add("Sample");
  
  // Create an a table named SalesTable on the Sample worksheet.
  let expensesTable = sheet.tables.add("A1:E1", true);
  expensesTable.name = "SalesTable";

  expensesTable.getHeaderRowRange().values = [["Product", "Qtr1", "Qtr2", "Qtr3", "Qtr4"]];        
  expensesTable.rows.add(null, [
    ["Frames", 5000, 7000, 6544, 4377],
    ["Saddles", 400, 323, 276, 651],
    ["Brake levers", 12000, 8766, 8456, 9812],
    ["Chains", 1550, 1088, 692, 853],
    ["Mirrors", 225, 600, 923, 544],
    ["Spokes", 6005, 7634, 4589, 8765]
  ]);
  
  sheet.getUsedRange().format.autofitColumns();
  sheet.getUsedRange().format.autofitRows();
  sheet.activate();

  // Create a line chart based on data from SalesTable.
  let dataRange = sheet.getRange("A1:E7");
  let chart = sheet.charts.add("Line", dataRange, Excel.ChartSeriesBy.rows);

  // Position and style the chart.
  chart.setPosition("A15", "E30");
  chart.legend.position = "Right";
  chart.legend.format.fill.setSolidColor("white");

  await context.sync();
});

字段

auto = "Auto"

在桌面版 Excel 中,“自动”选项将检查源数据形状,以自动猜测数据是按行还是按列。 在Excel web 版中,“auto”将仅默认为“columns”。

columns = "Columns"
rows = "Rows"