Skip to main content

DataLabels

Struct DataLabels 

Source
pub struct DataLabels {
    pub show_val: Option<bool>,
    pub show_cat_name: Option<bool>,
    pub show_ser_name: Option<bool>,
    pub show_legend_key: Option<bool>,
    pub show_percent: Option<bool>,
    pub show_bubble_size: Option<bool>,
    pub position: Option<LabelPosition>,
    pub separator: Option<String>,
    pub num_fmt: Option<String>,
}
Expand description

数据标签配置(<c:dLbls>),对应 OOXML CT_DLbls。

控制数据点数值/类别/系列名等标签的显示。可挂在图表级(<c:barChart> 内) 或系列级(<c:ser> 内)——系列级会覆盖图表级。

§字段语义

所有 show_* 字段为 Option<bool>

  • None:不写出该 <c:showXxx> 元素(继承上层或 PowerPoint 默认);
  • Some(true):写出 <c:showXxx val="1"/>
  • Some(false):写出 <c:showXxx val="0"/>

§与 python-pptx 的对应

  • python-pptx plot.data_labels ←→ 图表级 ChartData.data_labels
  • python-pptx series.data_labels ←→ 系列级 ChartSeries.data_labels

Fields§

§show_val: Option<bool>

显示数值(<c:showVal val="1"/>)。最常用的数据标签。

§show_cat_name: Option<bool>

显示类别名(<c:showCatName val="1"/>)。

§show_ser_name: Option<bool>

显示系列名(<c:showSerName val="1"/>)。

§show_legend_key: Option<bool>

显示图例键(<c:showLegendKey val="1"/>,图例色块前缀)。

§show_percent: Option<bool>

显示百分比(<c:showPercent val="1"/>,主要用于饼图)。

§show_bubble_size: Option<bool>

显示气泡尺寸(<c:showBubbleSize val="1"/>,仅气泡图)。

§position: Option<LabelPosition>

标签位置(<c:dLblPos val="..."/>)。

§separator: Option<String>

分隔符(<c:separator val="..."/>,如 ", " / "\n")。

§num_fmt: Option<String>

数字格式(<c:numFmt formatCode="..." sourceLinked="0"/>)。

Implementations§

Source§

impl DataLabels

Source

pub fn show_values() -> Self

新建一个仅显示数值的数据标签配置(最常用场景)。

Source

pub fn show_percent_pie() -> Self

新建一个显示百分比的饼图数据标签配置。

Source

pub fn write_xml(&self, w: &mut XmlWriter)

写出 <c:dLbls> 元素到 XmlWriter。

OOXML 元素顺序约束(ECMA-376 21.2.2.40): numFmtspacingpositionseparatorshowLegendKeyshowValshowCatNameshowSerNameshowPercentshowBubbleSizedLbldLblPos → …

实际 PowerPoint 实践中常用顺序:showValshowCatName → … → dLblPosseparatornumFmt。 本实现采用 PowerPoint 实践顺序以保证兼容性。

Source

pub fn is_empty(&self) -> bool

是否所有字段都为 None(即写出后只有空 <c:dLbls/>,无意义)。

Trait Implementations§

Source§

impl Clone for DataLabels

Source§

fn clone(&self) -> DataLabels

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataLabels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DataLabels

Source§

fn default() -> DataLabels

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V