DOCX

图表

在文档中添加图表 — 柱状图、折线图、饼图、圆环图、雷达图、气泡图等

使用 chart 在文档中嵌入图表。图表使用扁平的选项对象 — 直接传入 typecategoriesseries

基本柱状图

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "children": [
              {
                "chart": {
                  "type": "column",
                  "categories": ["Q1", "Q2", "Q3", "Q4"],
                  "series": [{ "name": "Sales", "values": [10, 20, 15, 25] }],
                  "title": "季度销售额",
                  "transformation": { "width": "13.2cm", "height": "7.9cm" }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

图表类型

type 属性选择图表类型:

类型
柱状图"column"
条形图"bar"
折线图"line"
饼图"pie"
面积图"area"
散点图"scatter"
圆环图"doughnut"
雷达图"radar"
气泡图"bubble"
股票图"stock"
曲面图"surface"

设置 threeD: true 可将柱状图、条形图、折线图、饼图、面积图转为 3D 变体。

多系列图表

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "children": [
              {
                "chart": {
                  "type": "column",
                  "categories": ["Q1", "Q2", "Q3", "Q4"],
                  "series": [
                    { "name": "产品 A", "values": [10, 20, 15, 25] },
                    { "name": "产品 B", "values": [15, 10, 20, 30] }
                  ],
                  "transformation": { "width": "13.2cm", "height": "7.9cm" }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

折线图

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "children": [
              {
                "chart": {
                  "type": "line",
                  "categories": ["一月", "二月", "三月", "四月", "五月"],
                  "series": [{ "name": "收入", "values": [100, 150, 200, 180, 250] }],
                  "transformation": { "width": "13.2cm", "height": "7.9cm" }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

饼图

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "children": [
              {
                "chart": {
                  "type": "pie",
                  "categories": ["桌面端", "移动端", "平板"],
                  "series": [{ "name": "流量", "values": [50, 35, 15] }],
                  "transformation": { "width": "10.6cm", "height": "7.9cm" }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

散点图

散点图使用 xValuesyValues 而非 categories

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "children": [
              {
                "chart": {
                  "type": "scatter",
                  "categories": [],
                  "series": [
                    {
                      "name": "数据集 1",
                      "values": [],
                      "xValues": [1, 2, 3, 4, 5],
                      "yValues": [2, 4, 1, 5, 3]
                    }
                  ],
                  "transformation": { "width": "13.2cm", "height": "7.9cm" }
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

chart 选项

选项类型说明
typestring图表类型(见上表)
categoriesstring[]类别标签
series{ name, values }[]系列数据
transformation{ width, height }显示尺寸
titlestring图表标题
showLegendboolean是否显示图例(默认:true
stylenumber样式预设(2–48)
threeDboolean启用 3D 渲染
floatingobject浮动定位选项
Copyright © 2026