OfficeCLI 折线图全能力指南:用 charts-line 示例玩转 line/stackedLine/percentStackedLine/line3d

发布时间:2026/9/19 15:15:10
OfficeCLI 折线图全能力指南:用 charts-line 示例玩转 line/stackedLine/percentStackedLine/line3d OfficeCLI 折线图全能力指南用 charts-line 示例玩转 line/stackedLine/percentStackedLine/line3d【免费下载链接】OfficeCLIOfficeCLI 是首款也是最佳的专为 AI 代理设计的命令行工具可用于读取、编辑和自动化处理 Word、Excel 和 PowerPoint 文件。它免费、开源仅包含一个二进制文件无需安装 Office 套件。项目地址: https://gitcode.com/iOfficeAI/OfficeCLIOfficeCLI 是专为 AI Agent 设计的命令行办公文档工具可对 Word、Excel、PowerPoint 文件进行读取、编辑与自动化处理。本文以仓库中的 charts-line.md 示例文档为核心系统讲解如何在 PowerPoint 中通过一行行 CLI 命令生成八张幻灯片、32 个折线图覆盖折线图变体、数据标记、平滑曲线、虚线样式、标题与图例、数据标签、坐标轴、覆盖图层参考线/趋势线/误差线等以及逐序列精调等全部核心能力。读完本文你将掌握officecli add/set/query/get在折线图场景下的完整参数体系并能直接用命令或 Python SDK 产出可交付的演示文稿。示例文件构成与快速复现折线图示例由三个配套文件组成全部位于examples/ppt/charts/目录charts-line.md本指南对应的说明文档将每张幻灯片映射到它演示的功能点charts-line.pyPython 脚本通过officecli命令生成演示文稿SDK 版charts-line.pptx生成的 8 页幻灯片每页 4 个图表共 32 个折线图。快速复现cd examples/ppt/charts python3 charts-line.py # → charts-line.pptx仓库还提供了完全等价的 bash 版本 charts-line.sh两者生成相同的charts-line.pptx。脚本中有意不启用set -e与 SDK 版doc.batch(...)的容错行为保持一致遇到向前兼容的UNSUPPORTED props警告officecli 退出码 2时继续构建保证完整文档被产出。运行环境与两种调用方式officecli是单二进制命令行工具无需安装 Office 套件。调用方式有两种方式一纯 CLIcharts-line.sh 演示officecli create charts-line.pptx officecli open charts-line.pptx officecli add charts-line.pptx / --type slide officecli add charts-line.pptx /slide[1] --type chart --prop chartTypeline ... officecli close charts-line.pptx officecli validate charts-line.pptx方式二Python SDKcharts-line.py 演示import officecli # pip install officecli-sdk同时需将 officecli 二进制加入 PATH with officecli.create(charts-line.pptx, --force) as doc: doc.batch([...]) # 批量提交 {command,parent,type,props} 字典SDK 版启动一个常驻进程每页的形状与图表通过命名管道在doc.batch(...)往返中发送每个条目与officecli batch列表中的{command,parent,type,props}字典完全一致。不支持的属性会原样转发常驻进程仅给出向前兼容警告而不中断批处理。若未安装 SDK脚本会自动回退到仓库内的sdk/python副本。通用数据与页面骨架所有图表共用一组数据约定CATSMon,Tue,Wed,Thu,Fri # 分类轴X 轴标签 D2A:50,60,70,65,80;B:40,45,55,60,75 # 多序列内联数据 # 格式系列名:数值列表多个系列用分号分隔根据 chart.json 中的data与categories属性说明data为「系列内联数据说明」支持Name:1,2,3或Name1:1,2,3;Name2:4,5,6两种写法仅限 Add 时使用categories为逗号分隔的分类标签也支持单元格区域引用如Sheet1!$A$2:$A$5。创建图表后再改序列数据应使用chart-series元素的 Set 操作。每页四个图表以象限布局排布TL/TR/BL/BR规格如下位置xywidthheight左上0.3in1.05in6.1in3in右上6.95in1.05in6.1in3in左下0.3in4.25in6.1in3in右下6.95in4.25in6.1in3in坐标与尺寸支持cm/in/pt/EMU单位见 chart.pptx-xlsx.json 中x/y/width/height的类型说明本文示例统一使用英寸。Slide 1四种折线图变体chartType第一页在同一数据上对比四种变体是理解chartType参数的最佳入口CATSMon,Tue,Wed,Thu,Fri D2A:50,60,70,65,80;B:40,45,55,60,75 officecli add charts-line.pptx /slide[1] --type chart \ --prop chartTypeline --prop titleline --prop legendbottom \ --prop categories$CATS --prop data$D2 \ --prop x0.3in --prop y1.05in --prop width6.1in --prop height3in officecli add charts-line.pptx /slide[1] --type chart \ --prop chartTypestackedLine --prop titlestackedLine --prop legendbottom \ --prop categories$CATS --prop data$D2 \ --prop x6.95in --prop y1.05in --prop width6.1in --prop height3in officecli add charts-line.pptx /slide[1] --type chart \ --prop chartTypepercentStackedLine --prop titlepercentStackedLine \ --prop legendbottom --prop categories$CATS --prop data$D2 \ --prop x0.3in --prop y4.25in --prop width6.1in --prop height3in officecli add charts-line.pptx /slide[1] --type chart \ --prop chartTypeline3d --prop titleline3d --prop legendbottom \ --prop categories$CATS --prop data$D2 \ --prop x6.95in --prop y4.25in --prop width6.1in --prop height3in关于 chartType 的重要限制根据 chart.json 的说明chartType是一个仅创建时生效add: true, set: false的枚举属性图表类型在创建时固定事后切换需要重建图表 XML各类型的序列与坐标轴结构不同因此正确做法是删除后重新添加或使用combotypes实现按序列覆盖类型。输入是宽松的接受友好别名stackedLine、percentStackedLine、line3d等并支持3d后缀、stacked前缀、percentStacked前缀三类修饰符组合但Get回读刻意不与输入对称——它返回系统的base_modifier记号形式例如line_stacked、line_percentStacked这是设计使然。本页功能点chartType的 line / stackedLine / percentStackedLine / line3d 四种取值。Slide 2数据标记marker / showMarker / linewidth数据标记让折线图的每个数据点清晰可见marker支持symbol:size:color复合格式# 显式标记符号:尺寸:颜色 officecli add charts-line.pptx /slide[2] --type chart \ --prop chartTypeline --prop titlemarkercircle:8:FF0000 \ --prop markercircle:8:FF0000 --prop linewidth2 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 officecli add charts-line.pptx /slide[2] --type chart \ --prop chartTypeline --prop titlemarkersquare:6 \ --prop markersquare:6 --prop linewidth2 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 officecli add charts-line.pptx /slide[2] --type chart \ --prop chartTypeline --prop titlemarkerdiamond:10:0070C0 \ --prop markerdiamond:10:0070C0 --prop linewidth2 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 # showMarkertrue使用默认自动标记 officecli add charts-line.pptx /slide[2] --type chart \ --prop chartTypeline --prop titleshowMarkertrue (default markers) \ --prop showMarkertrue --prop legendbottom \ --prop categories$CATS --prop data$D2marker 参数细节根据 chart.json 的marker属性说明仅对line / scatter / radar系列生效其他图表类型被静默跳过格式为symbol、symbol:size或symbol:size:color三档可选符号none, auto, circle, square, diamond, triangle, x, plus, star, dash, dot图片型标记未实现markersize独立取值范围为 2..72markercolor可单独设置填充色且保留原有符号与尺寸图表级showMarkertrue是在创建后为所有 line/scatter 系列打开标记的开关add: false, set: true会使用默认自动标记。本页功能点markersymbol:size:color 复合格式、符号 circle/square/diamond/triangle/star/…、showMarkertrue自动标记、linewidth线宽单位 pt。Slide 3平滑曲线与虚线样式smooth / linedash# 平滑曲线 officecli add charts-line.pptx /slide[3] --type chart \ --prop chartTypeline --prop titlesmoothtrue \ --prop smoothtrue --prop linewidth2.5 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 # 虚线样式 officecli add charts-line.pptx /slide[3] --type chart \ --prop chartTypeline --prop titlelinedashdash \ --prop linedashdash --prop linewidth2 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 officecli add charts-line.pptx /slide[3] --type chart \ --prop chartTypeline --prop titlelinedashdot \ --prop linedashdot --prop linewidth2 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 officecli add charts-line.pptx /slide[3] --type chart \ --prop chartTypeline --prop titlelinedashdashDot \ --prop linedashdashDot --prop linewidth2 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80smooth 与 linedash 的取值约束smooth仅适用于 line/scatter 图表见 chart.json 的appliesWhen在其他图表类型上会报告不支持值为true|false表示是否启用平滑曲线插值。linedash作用于所有序列的线型可选值solid, dash, dashDot, dot, lgDash, lgDashDot, sysDash, sysDot, sysDashDot文档示例使用 dash / dot / dashDot 等友好别名chart-series.json 的lineDash枚举还包含 longDash 等更多取值。linewidth线宽单位为 pt可传浮点数如 2.5作用于每条序列线。本页功能点smooth、linewidthpt 浮点、linedashsolid/dash/dot/dashDot/longDash/longDashDot/longDashDotDot。Slide 4标题与图例title.* / legend / autotitledeletedofficecli add charts-line.pptx /slide[4] --type chart \ --prop chartTypeline --prop titleStyled title \ --prop title.fontGeorgia --prop title.size20 \ --prop title.color4472C4 --prop title.boldtrue \ --prop legendbottom --prop categories$CATS --prop data$D2 officecli add charts-line.pptx /slide[4] --type chart \ --prop chartTypeline --prop titlelegendtop legendFont \ --prop legendtop --prop legendFont10:333333:Calibri \ --prop categories$CATS --prop data$D2 officecli add charts-line.pptx /slide[4] --type chart \ --prop chartTypeline --prop titlelegend.overlaytrue \ --prop legendtopRight --prop legend.overlaytrue \ --prop categories$CATS --prop data$D2 officecli add charts-line.pptx /slide[4] --type chart \ --prop chartTypeline --prop autotitledeletedtrue --prop legendnone \ --prop categories$CATS --prop data$D2标题与图例属性速查根据 chart.json 的属性定义属性说明示例title图表标题文本传none或空串可省略/删除标题--prop title2024 Salestitle.font标题字体名--prop title.fontGeorgiatitle.size标题字号如 14 或 14pt--prop title.size20title.color标题颜色#RRGGBB、命名色或主题色--prop title.color4472C4title.bold标题加粗true/false--prop title.boldtruetitle.overlay标题覆盖绘图区而非预留上方空间--prop title.overlaytruelegend图例位置none/false 隐藏top/bottom/left/right/topRight(tr)--prop legendbottomlegendFont图例字体格式size:color:fontname各段可省略--prop legendFont10:333333:Calibrilegend.overlay图例覆盖绘图区而非预留空间--prop legend.overlaytrueautotitledeleted抑制自动生成的「图表标题」占位符--prop autotitledeletedtrue注意legendFont的复合格式为字号:颜色:字体与labelfont、axisfont保持一致的分段风格任意段可省略。图例位置还接受连字符与下划线变体。本页功能点title.font/size/color/bold、legend各位置、legendFont、legend.overlay、autotitledeleted。Slide 5数据标签dataLabels / labelPos / labelfontofficecli add charts-line.pptx /slide[5] --type chart \ --prop chartTypeline --prop titledataLabelsvalue top \ --prop dataLabelsvalue --prop labelPostop \ --prop labelfont10:333333:Calibri --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 officecli add charts-line.pptx /slide[5] --type chart \ --prop chartTypeline --prop titlevalue,category \ --prop dataLabelsvalue,category --prop labelPostop --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 officecli add charts-line.pptx /slide[5] --type chart \ --prop chartTypeline --prop titledataLabelsnone \ --prop dataLabelsnone --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 officecli add charts-line.pptx /slide[5] --type chart \ --prop chartTypeline --prop titlelabelfont styled \ --prop dataLabelsvalue --prop labelPostop \ --prop labelfont12:C00000:Georgia --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80dataLabels 与 labelPos 规则dataLabels用none隐藏否则传逗号分隔的标志列表value, percent, category, series, all也接受seriesName/categoryName/percentage/values别名。位置类取值outsideEnd/center/insideEnd/insideBase/top/bottom/left/right/bestFit会隐式启用showVal并作为dLblPos应用。labelPos数据标签位置可选center|ctr, insideEnd|inEnd|inside, insideBase|inBase|base, outsideEnd|outEnd|outside, bestFit|best|auto, top|t, bottom|b, left|l, right|r。注意限制doughnut/area/radar/stock 不支持pie/pie3D 仅限 ctr/inEnd/inBase/bestFit堆叠系列会被钳制到 ctr/inBase/inEnd。labelfont数据标签字体格式size:color:fontname回读时按labelFont.size/color/bold/name拆分为独立键便于 dump→replay 重建。本页功能点dataLabelsvalue/category/none 或组合、labelPostop/center/insideEnd/outsideEnd/bestFit、labelfont。Slide 6坐标轴min/max、网格线、刻度、旋转、对数坐标轴是折线图信息密度最高的部分示例拆成四组展示# 坐标轴缩放、标题、数字格式 officecli add charts-line.pptx /slide[6] --type chart \ --prop chartTypeline --prop titlemin/max titles --prop legendnone \ --prop axismin0 --prop axismax100 --prop majorunit25 \ --prop axistitleVisits --prop cattitleDay \ --prop axisfont10:333333:Calibri --prop axisline666666:1 \ --prop axisnumfmt#,##0 \ --prop categories$CATS --prop dataA:50,60,70,65,80 # 网格线与刻度 officecli add charts-line.pptx /slide[6] --type chart \ --prop chartTypeline --prop titlegridlines ticks --prop legendnone \ --prop gridlinesE0E0E0:0.3 --prop minorGridlinesF0F0F0:0.25 \ --prop majorTickMarkout --prop minorTickMarkin --prop tickLabelPosnextTo \ --prop categories$CATS --prop dataA:50,60,70,65,80 # 标签旋转 officecli add charts-line.pptx /slide[6] --type chart \ --prop chartTypeline --prop titlelabelrotation-30 --prop legendnone \ --prop labelrotation-30 \ --prop categoriesJanuary,February,March,April,May,June \ --prop dataA:60,90,140,180,160,210 # 数值轴对数刻度 officecli add charts-line.pptx /slide[6] --type chart \ --prop chartTypeline --prop titlelogbase10 --prop legendnone \ --prop logbase10 --prop axismin1 --prop axismax10000 \ --prop categories$CATS --prop dataGrowth:5,50,500,5000,3000坐标轴参数详解文档中的图表级axis*属性实际上是 chart-axis.json 中坐标轴元素的便捷快捷方式。以 chart.json 为准各参数说明如下属性类型/取值说明axismin/axismaxnumber数值轴最小值/最大值快捷方式对应 axis 元素的min/max仅 rolevalue/value2 有效majorunit/minorunitnumber数值轴主/次网格线与刻度间距axistitle/cattitlestring数值轴标题 / 分类轴标题cattitle别名htitleaxisfontstring坐标轴字体格式size:color:fontnameaxislinestring坐标轴线格式color:width[:dash]axisnumfmtstring数值轴数字格式如#,##0gridlines/minorGridlinesbool 或color[:width[:dash]]数值轴主/次网格线可用none移除majorTickMark/minorTickMarkout/in/cross/none主/次刻度样式tickLabelPoshigh/low/nextTo/none刻度标签位置labelrotationnumber-90..90刻度标签旋转角度裸写同时作用于双轴xaxis.labelrotation仅分类轴yaxis./valaxis.labelrotation仅数值轴logbasenumber通常 2..1000数值轴对数底简写true/yes/log/1→ 底 10false/none/linear/0移除对数刻度坐标轴的后置调整值得注意的是图表级axis*参数是Add 时专用pptx/chart.json 的 note 明确说明 axis* props 为 Add-time only。创建之后如需调整坐标轴应通过chart-axis元素定位officecli set charts-line.pptx /slide[6]/chart[1]/axis[rolevalue] \ --prop max100 --prop min0 --prop logBase10chart-axis的路径片段为axisrole 支持 category/value/value2/series见 pptx/chart.json 的 children 定义。本页功能点axismin/max、majorunit、axistitle/cattitle、axisfont/axisline/axisnumfmt、gridlines/minorGridlines、majorTickMark/minorTickMark/tickLabelPos、labelrotation、logbase。Slide 7覆盖图层droplines / hilowlines / updownbars / trendline / errbars / referenceline折线图叠加层让趋势分析、范围展示与阈值监控一气呵成# 垂直线 高低线 officecli add charts-line.pptx /slide[7] --type chart \ --prop chartTypeline --prop titledroplines hilowlines \ --prop droplines808080:0.5 --prop hilowlinestrue \ --prop legendbottom \ --prop categories$CATS \ --prop dataHigh:130,135,140,138,145;Low:118,122,128,125,132 # 涨跌柱自定义颜色 officecli add charts-line.pptx /slide[7] --type chart \ --prop chartTypeline --prop titleupdownbars150:00AA00:FF0000 \ --prop updownbars150:00AA00:FF0000 --prop legendbottom \ --prop categories$CATS \ --prop dataOpen:120,128,130,135,138;Close:128,125,135,138,142 # 趋势线 误差线 officecli add charts-line.pptx /slide[7] --type chart \ --prop chartTypeline --prop titletrendlinelinear errbarsstdDev:1 \ --prop trendlinelinear --prop errbarsstdDev:1 --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80 # 参考线水平阈值 officecli add charts-line.pptx /slide[7] --type chart \ --prop chartTypeline --prop titlereferenceline70:FF0000:Target \ --prop referenceline70:FF0000:Target --prop legendnone \ --prop categories$CATS --prop dataA:50,60,70,65,80各覆盖层参数格式droplines折线图专属appliesWhen: line。true|false开关或线样式color[:width[:dash]]none移除。示例808080:0.5为灰色 0.5pt 垂直线。hilowlinesline/stock 图高低线格式同 droplines。updownbarsline/stock 图涨跌柱。true、gapWidth:upColor:downColor或none/false。示例150:00AA00:FF0000为 150% 间隙、绿色上涨、红色下跌。trendline为每个序列添加趋势线。格式type[:order]或type:forward:backward。类型linear默认、exp|exponential、log|logarithmic、poly|polynomial、power、movingAvg|moving|movingAverageorder 适用于 poly/movingAvgnone清除。errbars误差线格式type:valuetype ∈fixed|fixedValue、percent|percentage|pct、stddev|standardDeviation、stderr|standardErrornone移除。示例stdDev:1为一个标准差。referenceline水平参考/目标线格式value、value:color、value:color:label或value:color:label:dashnone移除。示例70:FF0000:Target在 70 处画红色「Target」参考线。本页功能点droplinescolor:width、hilowlinestrue 或 color:width、updownbarsgapWidth:upColor:downColor、trendlinelinear/…、errbars、referencelinevalue:color:label。Slide 8样式预设与逐序列精调preset / chart-series Set最后一页演示两种「批量 → 精调」的生产级工作流先用preset一键套用整套配色风格再用set命令对单个系列做像素级定制。for p in minimal dark corporate; do officecli add charts-line.pptx /slide[8] --type chart \ --prop chartTypeline --prop preset$p --prop titlepreset$p \ --prop legendbottom --prop categories$CATS --prop data$D2 done officecli add charts-line.pptx /slide[8] --type chart \ --prop chartTypeline --prop titlechart-series Set per line \ --prop showMarkertrue --prop legendbottom \ --prop categories$CATS --prop data$D2 # 逐序列修改线宽、线型、标记、标记尺寸、平滑 officecli set charts-line.pptx /slide[8]/chart[4]/series[1] \ --prop nameAlpha --prop colorC00000 --prop lineWidth2.5 \ --prop lineDashsolid --prop markercircle --prop markerSize9 \ --prop smoothtrue officecli set charts-line.pptx /slide[8]/chart[4]/series[2] \ --prop nameBeta --prop color2E75B6 --prop lineWidth1.5 \ --prop lineDashdash --prop markerdiamond --prop markerSize8preset 预设根据 chart.json 的preset属性命名样式包可选值minimal, dark, corporate, magazine, dashboard, colorful, monochrome(mono)。示例中遍历了 minimal / dark / corporate 三种用于快速产出风格统一的多图表页面。逐序列 set 详解chart-series元素支持位置路径/slide[N]/chart[N]/series[N]与稳定路径/slide[N]/chart[idID]/series[idID]见 pptx/chart-series.json。可用的逐序列属性chart-series.json属性取值/格式说明namestring系列名图例与数据标签显示别名titlecolor#RRGGBB系列填充/线条颜色回读为 # 前缀大写十六进制lineWidthnumber系列线宽pt可浮点如 1.5lineDashsolid/dash/dot/dashDot/longDash/…系列线型Set 接受友好别名Get 返回 OOXML 记号sysDash/sysDot/sysDashDot/lgDashsolid是唯一可稳定往返的值marker符号或symbol:size:COLOR系列标记line/scatter/radarmarkerSize2..72标记尺寸marker 非 none 时生效markerColor颜色标记填充色保留原符号与尺寸smoothtrue/false该系列是否平滑仅 line/scatter注意 pptx/chart-series.json 的提示Add 时系列以父图表的点分属性传入series1.name、series1.values、series1.color、series1.categories而创建后的逐系列 Set/Get 才走chart-series元素lineStyle不是合法键会被拒绝为 UNSUPPORTED请改用lineWidth lineDash组合图混合类型/次坐标轴暂不支持需要分开建图。本页功能点preset、chart-series Set 的name/color/lineWidth/lineDash/marker/markerSize/smooth。功能覆盖总览功能对应幻灯片图表类型line, stackedLine, percentStackedLine, line3d1markersymbol:size:color 复合格式2showMarker自动标记2linewidth2, 3smooth3linedashsolid/dash/dot/dashDot/longDash/…3title.font/size/color/bold4legend位置、legendFont、legend.overlay4autotitledeleted4dataLabelsvalue/category/none 组合5labelPostop/center/insideEnd/outsideEnd5labelfont5axismin/max、majorunit、axistitle/cattitle6axisfont/axisline/axisnumfmt6gridlines/minorGridlines、刻度样式6labelrotation、logbase6droplines7hilowlines7updownbarsgapWidth:upColor:downColor7trendline、errbars7referenceline7preset8chart-series SetlineWidth/lineDash/marker/markerSize/smooth8验证生成的演示文稿构建完成后可用query与get命令验证内部结构与属性回读officecli query charts-line.pptx chart officecli get charts-line.pptx /slide[1]/chart[1] officecli get charts-line.pptx /slide[7]/chart[1] officecli get charts-line.pptx /slide[8]/chart[4]/series[1]几点预期chartType的 Get 回读是line_stacked这类系统化base_modifier记号而非输入别名showMarker、smooth回读为 true/falseseries的lineDash回读为 OOXML 记号。结合 图表示例总览 与其他 charts 子目录 的柱状图、面积图、组合图示例可进一步构建覆盖全部图表类型的演示矩阵。延伸阅读charts-line.py — 本文全部命令的 Python SDK 等价实现doc.batch批量构建charts-line.sh — 纯 CLI 等价实现含validate校验步骤chart.json — 图表级属性的完整 Schema含所有别名、appliesWhen 与回读格式pptx/chart.json — pptx 图表元素的操作能力与路径约定chart-series.json — 逐序列属性的完整 Schemachart-axis.json — 坐标轴元素的 Set/Get 属性sdk/python/README.md — officecli Python SDK 安装与使用说明。【免费下载链接】OfficeCLIOfficeCLI 是首款也是最佳的专为 AI 代理设计的命令行工具可用于读取、编辑和自动化处理 Word、Excel 和 PowerPoint 文件。它免费、开源仅包含一个二进制文件无需安装 Office 套件。项目地址: https://gitcode.com/iOfficeAI/OfficeCLI创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考