在 Java 中管理簡報的圖表資料系列

概述

圖表可以將其繪製的數值儲存在工作簿儲存格中,或直接作為數值文字常數。IChartSeries 代表一組相關的數值,而每個 IChartDataPoint 代表該系列中的一個點。IChartCategory 物件提供系列共用的標籤或分組值。對於使用預設資料建立的圖表,系列名稱、類別以及點值使用來自圖表工作簿的 IChartDataCell 物件。

對於一般的類別圖表,預設工作簿使用第 0 列作為系列名稱,第 0 欄作為類別名稱,剩餘儲存格則存放系列值。傳遞給 IChartDataWorkbook.getCell 的工作表、列與欄索引採零基礎。此佈局在建立預設資料圖表時很有用,但不要假設每個已存在的圖表都使用該佈局。對於已載入的簡報,請在變更工作簿值之前,先檢查系列、類別與資料點所參照的儲存格。

圖表設定有三種不同的範圍:

當未明確設定點或系列的填滿時,圖表樣式與佈景主題會決定自動外觀。當同時存在系列與點的格式設定時,點的格式設定會優先套用於該點。

chart-series-powerpoint

對於叢集圓柱圖,請參閱 變更 3D 系列類型或長條形狀 如何影響第一個系列。

使用數值文字常數設定系列值

當系列值來自應用程式資料或計算且不需要工作表儲存格參照時,請使用數值文字常數。先以 DataSourceType.DoubleLiterals 呼叫 setDataSourceTypeForValues,再透過 setAsLiteralDouble 為每個點的 getValue 結果指定數值。

此集合設定會控制該系列中所有點值的來源類型。每個點值的 getDataSourceType 方法會回報所選類型;可透過集合設定變更。若使用 Worksheet,請使用 getAsCell 取得參照的儲存格。若使用 DoubleLiterals,請使用 getAsLiteralDouble 或 setAsLiteralDouble 直接讀寫數字。

以下範例建立一個採用預設系列與類別的直條圖,然後將計算出的 10、20 等值指派給其第一個系列中已存在的點。程式會儲存簡報、重新開啟,並列印儲存的值。

import com.aspose.slides.*;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 300);
    IChartSeries series = chart.getChartData().getSeries().get_Item(0);

    series.getDataPoints().setDataSourceTypeForValues(DataSourceType.DoubleLiterals);
    for (int i = 0; i < series.getDataPoints().size(); i++) {
        series.getDataPoints().get_Item(i).getValue().setAsLiteralDouble((i + 1) * 10);
    }

    presentation.save("numeric_literals.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Presentation reopenedPresentation = new Presentation("numeric_literals.pptx");
try {
    ISlide reopenedSlide = reopenedPresentation.getSlides().get_Item(0);
    IChart reopenedChart = (IChart) reopenedSlide.getShapes().get_Item(0);
    IChartSeries reopenedSeries = reopenedChart.getChartData().getSeries().get_Item(0);
    for (IChartDataPoint point : reopenedSeries.getDataPoints()) {
        System.out.println(point.getValue().getAsLiteralDouble());
    }
} finally {
    reopenedPresentation.dispose();
}

點值的來源類型與 IChartData.getDataSourceType 分開,後者識別圖表的內部或外部工作簿設定。使用數值文字常數本身不會移除內嵌工作簿。在此範例中,工作簿仍保留用於類別標籤、系列名稱與其他系列。請參閱 圖表工作簿 了解工作簿管理。

對於散佈圖與氣泡圖,請使用 setDataSourceTypeForXValues 與 setDataSourceTypeForYValues 來選擇 getXValue 與 getYValue 的來源。氣泡圖亦使用 setDataSourceTypeForBubbleSizes 來設定 getBubbleSize 的來源。於指派數字前,先將每個適用的來源設定為 DoubleLiterals,再使用該值的 setAsLiteralDouble 方法。

設定圖表系列重疊

IChartSeries.getOverlap 會回報 2D 圖表中長條或柱狀的重疊程度,範圍為 -100 至 100%。它是父系列群組設定的唯讀投影。使用 IChartSeriesGroup.setOverlap 可更新該群組中所有相容的系列。此選項僅套用於顯示分組長條或柱狀的圖表類型;不會影響組合圖中與之無關的系列群組。

以下範例為包含第一個系列的群組設定重疊:

import com.aspose.slides.*;

final int firstSlideIndex = 0;
final int firstSeriesIndex = 0;
final byte overlapPercent = 30;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    // 新圖表包含範例系列、類別和數值。
    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);

    IChartSeries series = chart.getChartData().getSeries().get_Item(firstSeriesIndex);
    series.getParentSeriesGroup().setOverlap(overlapPercent);

    presentation.save("series_overlap.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

結果:

The series overlap

變更系列填滿色彩

使用 IChartSeries.getFormat 可為整個系列設定預設填滿。若某個點已明確設定填滿,則其 IChartDataPoint.getFormat 會覆寫該系列的填滿。

以下範例為第一個系列套用實心藍色填滿:

import com.aspose.slides.*;
import java.awt.Color;

final int firstSlideIndex = 0;
final int firstSeriesIndex = 0;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);

    IChartSeries series = chart.getChartData().getSeries().get_Item(firstSeriesIndex);
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(Color.BLUE);

    presentation.save("series_color.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

結果:

The color of the series

變更系列名稱

系列名稱儲存在圖表資料工作簿中,通常會顯示在圖例中。對於預設為叢集直條圖的工作簿,儲存格 B1(第 0 列第 1 欄)包含第一個系列的名稱。以下範例中的具名常數將此結構明確化:

import com.aspose.slides.*;

final int firstSlideIndex = 0;
final int worksheetIndex = 0;
final int seriesNameRowIndex = 0;
final int firstSeriesColumnIndex = 1;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);

    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, seriesNameRowIndex, firstSeriesColumnIndex);
    seriesNameCell.setValue("Revenue");

    presentation.save("series_name.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

您也可以直接更新由 IChartSeries.getName 參照的儲存格。此作法避免假設已存在圖表中的特定列與欄:

import com.aspose.slides.*;

final int firstSlideIndex = 0;
final int firstSeriesIndex = 0;
final int firstNameCellIndex = 0;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);

    IChartSeries series = chart.getChartData().getSeries().get_Item(firstSeriesIndex);
    IChartDataCell seriesNameCell = series.getName().getAsCells().get_Item(firstNameCellIndex);
    seriesNameCell.setValue("Revenue");

    presentation.save("series_name.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

結果:

The series name

使用多個儲存格建立具有名稱的系列

當產品名稱與報告期間分別儲存在不同工作簿儲存格時,複合系列名稱會很有用。例如,您可以將 B1 中的 Product A 與 C1 中的 2026 合併為單一系列名稱,同時保持兩個部份與其來源儲存格的連結。

使用 IChartDataWorkbook.getCellCollection 取得名稱範圍,然後將該集合傳遞給 IChartSeriesCollection.add。skipHiddenCells 參數決定是否排除隱藏儲存格:true 排除,false 包含。此範例使用 false 以包含名稱範圍中的每個儲存格。

以下範例建立一個包含一個系列與兩個資料點的簡報。儲存格 B1:C1 只提供系列名稱;A2:A3 提供類別標籤,B2:B3 提供數值。

import com.aspose.slides.*;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 620, 180);

    chart.getChartData().getSeries().clear();
    chart.getChartData().getCategories().clear();
    chart.setLegend(true);

    IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
    workbook.clear(0);

    // 這兩個儲存格提供系列名稱。
    workbook.getCell(0, 0, 1, "Product A");
    workbook.getCell(0, 0, 2, "2026");
    IChartCellCollection nameCells = workbook.getCellCollection("Sheet1!$B$1:$C$1", false);
    IChartSeries series = chart.getChartData().getSeries().add(nameCells, ChartType.ClusteredColumn);

    // 各別的儲存格提供類別與數值資料點。
    IChartDataCell northCategory = workbook.getCell(0, 1, 0, "North");
    IChartDataCell southCategory = workbook.getCell(0, 2, 0, "South");
    chart.getChartData().getCategories().add(northCategory);
    chart.getChartData().getCategories().add(southCategory);
    IChartDataCell northValue = workbook.getCell(0, 1, 1, 120);
    IChartDataCell southValue = workbook.getCell(0, 2, 1, 150);
    series.getDataPoints().addDataPointForBarSeries(northValue);
    series.getDataPoints().addDataPointForBarSeries(southValue);

    presentation.save("composite_series_name.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

最終的系列名稱為 Product A 2026,兩個儲存格值之間有一個空格。圖例會將其顯示為同一個項目。下圖說明了結果:

Column chart with North and South values and the composite series name Product A 2026 in the legend

取得自動系列填滿色彩

IChartSeries.getAutomaticSeriesColor 會回傳依系列索引與圖表樣式計算出的色彩。此色彩會在系列填滿未明確定義時使用。呼叫此方法只會讀取計算出的色彩,不會指派新的填滿。

以下範例列印每個預設系列的自動色彩:

import com.aspose.slides.*;
import java.awt.Color;

final int firstSlideIndex = 0;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);

    int seriesCount = chart.getChartData().getSeries().size();
    for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {
        IChartSeries series = chart.getChartData().getSeries().get_Item(seriesIndex);
        Color automaticColor = series.getAutomaticSeriesColor();
        System.out.println("Series " + seriesIndex + ": " + automaticColor);
    }
} finally {
    presentation.dispose();
}

預設圖表樣式的輸出範例:

Series 0: java.awt.Color[r=79,g=129,b=189]
Series 1: java.awt.Color[r=192,g=80,b=77]
Series 2: java.awt.Color[r=155,g=187,b=89]

實際色彩取決於圖表樣式與佈景主題。

為圖表系列設定負值反轉填滿色彩

對於長條、柱狀與氣泡系列,IChartSeries.setInvertIfNegative 可在負值時顯示不同的填滿。將常規系列填滿設為實心、啟用反轉,並透過 IChartSeries.getInvertedSolidFillColor 指定負值顏色。負數在工作簿中仍保持不變,僅其顯示顏色會改變。

以下範例以一個系列取代預設圖表資料。工作表第 0 列包含系列名稱,第 0 欄包含類別名稱,第 1 欄包含數值:

import com.aspose.slides.*;
import java.awt.Color;

final int firstSlideIndex = 0;
final int worksheetIndex = 0;
final int headerRowIndex = 0;
final int categoryColumnIndex = 0;
final int firstSeriesColumnIndex = 1;
final int firstDataRowIndex = 1;

String[] categoryNames = { "Category 1", "Category 2", "Category 3" };
int[] seriesValues = { -20, 50, -30 };

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);
    IChartData chartData = chart.getChartData();
    IChartDataWorkbook workbook = chartData.getChartDataWorkbook();

    chartData.getSeries().clear();
    chartData.getCategories().clear();

    IChartDataCell seriesNameCell = workbook.getCell(worksheetIndex, headerRowIndex, firstSeriesColumnIndex, "Series 1");
    int chartType = chart.getType();
    IChartSeries series = chartData.getSeries().add(seriesNameCell, chartType);

    for (int categoryIndex = 0; categoryIndex < categoryNames.length; categoryIndex++) {
        int dataRowIndex = firstDataRowIndex + categoryIndex;
        String categoryName = categoryNames[categoryIndex];
        int seriesValue = seriesValues[categoryIndex];

        IChartDataCell categoryCell = workbook.getCell(worksheetIndex, dataRowIndex, categoryColumnIndex, categoryName);
        chartData.getCategories().add(categoryCell);

        IChartDataCell valueCell = workbook.getCell(worksheetIndex, dataRowIndex, firstSeriesColumnIndex, seriesValue);
        series.getDataPoints().addDataPointForBarSeries(valueCell);
    }

    Color automaticSeriesColor = series.getAutomaticSeriesColor();
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(automaticSeriesColor);
    series.setInvertIfNegative(true);
    series.getInvertedSolidFillColor().setColor(Color.RED);

    presentation.save("inverted_solid_fill_color.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

結果:

The inverted solid fill color

您也可以透過 IChartDataPoint.setInvertIfNegative 為單一點啟用反轉。以下範例在系列層級關閉反轉,僅為選取的點啟用,並將該點指定為負值,以見效:

import com.aspose.slides.*;
import java.awt.Color;

final int firstSlideIndex = 0;
final int firstSeriesIndex = 0;
final int targetDataPointIndex = 2;
final int negativeValue = -30;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);

    IChartSeries series = chart.getChartData().getSeries().get_Item(firstSeriesIndex);
    Color automaticSeriesColor = series.getAutomaticSeriesColor();
    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(automaticSeriesColor);
    series.getInvertedSolidFillColor().setColor(Color.RED);
    series.setInvertIfNegative(false);

    IChartDataPoint dataPoint = series.getDataPoints().get_Item(targetDataPointIndex);
    dataPoint.getValue().getAsCell().setValue(negativeValue);
    dataPoint.setInvertIfNegative(true);

    presentation.save("data_point_invert_color_if_negative.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

清除特定資料點的值

若要使單一點變為空白而不移除其他點,請將其對應的工作簿儲存格設為 null。對於直條圖,繪製的值可透過 IChartDataPoint.getValue 取得。資料點仍保留在相同的類別位置,但圖表會根據空白值設定將其視為空白。

以下範例僅清除第一個系列的第二個點:

import com.aspose.slides.*;

final int firstSlideIndex = 0;
final int firstSeriesIndex = 0;
final int targetDataPointIndex = 1;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 200);

    IChartSeries series = chart.getChartData().getSeries().get_Item(firstSeriesIndex);
    IChartDataPoint dataPoint = series.getDataPoints().get_Item(targetDataPointIndex);
    dataPoint.getValue().getAsCell().setValue(null);

    presentation.save("clear_data_point_value.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

散佈圖使用分別的 X 與 Y 儲存格,氣泡圖亦使用尺寸儲存格。僅清除欲移除的值所對應的儲存格。若想保留其他點,請勿呼叫 IChartDataPointCollection.clear,因為該方法會移除該系列中的所有資料點。

控制空白儲存格的顯示

隱藏且含有數值的儲存格屬於另一種情況,與空白儲存格不同。若要包含或排除隱藏工作表列與欄的資料,請參閱 Include Data from Hidden Rows and Columns。

空白工作簿儲存格代表缺失的資料;儲存格內的 0 代表已知的數值。使用 IChartDataCell.setValue 並傳入 null 可使儲存格變為空白。數值零無論空白儲存格設定為何,都仍保留為零。

使用 IChart.setDisplayBlanksAs 可選擇圖表如何顯示空白儲存格。此設定套用於整個圖表,會改變空白的繪製方式,而不會將空白工作簿儲存格填入零或插值。

以下自含範例建立一個單系列折線圖,清除第 3 天的值,並以每種模式分別儲存同一圖表。此程式不需要輸入檔案。IChartDataWorkbook 使用工作表 0,第 0 欄做類別標籤,第 1 欄做數值;第 0 列保留系列名稱。最終資料為 10, 20, empty, 30, 40。

import com.aspose.slides.*;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 40, 40, 640, 400);
    IChartData chartData = chart.getChartData();
    IChartDataWorkbook workbook = chartData.getChartDataWorkbook();

    chartData.getSeries().clear();
    chartData.getCategories().clear();

    IChartDataCell seriesNameCell = workbook.getCell(0, 0, 1, "Measurements");
    IChartSeries series = chartData.getSeries().add(seriesNameCell, chart.getType());
    int[] values = { 10, 20, 25, 30, 40 };

    for (int i = 0; i < values.length; i++) {
        IChartDataCell categoryCell = workbook.getCell(0, i + 1, 0, "Day " + (i + 1));
        chartData.getCategories().add(categoryCell);
        IChartDataCell valueCell = workbook.getCell(0, i + 1, 1, values[i]);
        series.getDataPoints().addDataPointForLineSeries(valueCell);
    }

    // 將第 3 天真正留空,同時保留其類別和資料點。
    workbook.getCell(0, 3, 1).setValue(null);

    int[] modes = { DisplayBlanksAsType.Gap, DisplayBlanksAsType.Zero, DisplayBlanksAsType.Span };
    String[] modeNames = { "Gap", "Zero", "Span" };
    for (int i = 0; i < modes.length; i++) {
        chart.setDisplayBlanksAs(modes[i]);
        presentation.save("empty_cells_" + modeNames[i] + ".pptx", SaveFormat.Pptx);
    }
} finally {
    presentation.dispose();
}

每個輸出檔案皆在儲存前指定模式:empty_cells_Gap.pptx、empty_cells_Zero.pptx、empty_cells_Span.pptx。若只需一個版本,可在儲存簡報前指定所需模式,無需迭代所有模式。

下表比較三個檔案的相同資料。第 3 天在工作簿中皆為空白:

Line charts with identical data: Gap breaks the line at Day 3, Zero drops the line to zero, and Span connects Day 2 to Day 4.

可視效果取決於圖表類型。折線圖能清楚比較三種模式。長條與柱狀圖因沒有連線跨過缺失的類別,Span 無法產生如上所示的連接段落;缺失的柱狀與零高度的柱狀看起來也相似。類似地,僅有標記的散佈圖也沒有連線。請勿期望每種圖表類型都有三種明顯的結果;請依您使用的圖表類型檢查輸出。

設定系列間隙寬度

間隙寬度是相鄰長條或柱狀叢集之間的空間,以長條或柱狀寬度的百分比表示。與重疊相同,它屬於父系列群組而非單一系列。請對群組呼叫一次 IChartSeriesGroup.setGapWidth。較大的數值會在叢集之間產生較多空間,較小的數值則使叢集更緊密。

以下範例變更間隙寬度,並僅儲存最終簡報:

import com.aspose.slides.*;

final int firstSlideIndex = 0;
final int firstSeriesIndex = 0;
final int gapWidthPercent = 30;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(firstSlideIndex);

    IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 20, 20, 500, 200);

    IChartSeries series = chart.getChartData().getSeries().get_Item(firstSeriesIndex);
    series.getParentSeriesGroup().setGapWidth(gapWidthPercent);

    presentation.save("gap_width_30.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

結果:

The gap width

顯示或隱藏系列線條

系列線條在圖表中視覺上連接相關的部份。對於受支援的堆疊長條與堆疊圓餅圖,請使用 IChartSeriesGroup.setSeriesLines 來顯示或隱藏它們。在二維堆疊長條與柱狀圖中,系列線條會於類別間連接相對的堆疊邊界;在 Pie of Pie 與 Bar of Pie 圖表中,則連接主圖與次圖。此設定並非用於其他圖表類型的通用連接器。

請透過 IChartSeries.getParentSeriesGroup 取得群組。此設定會套用於該群組中的每個系列。IChartSeries.hasSeriesLines 為唯讀屬性,顯示父群組的設定;請呼叫群組的 Setter 進行更新。

以下範例建立一個使用預設資料的 PieOfPie 圖表,分別儲存啟用與關閉系列線條的兩個簡報,以供比較。

import com.aspose.slides.*;

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IChart chart = slide.getShapes().addChart(ChartType.PieOfPie, 50, 50, 600, 400);
    IChartSeries series = chart.getChartData().getSeries().get_Item(0);
    IChartSeriesGroup seriesGroup = series.getParentSeriesGroup();

    seriesGroup.setSeriesLines(true);
    presentation.save("series_lines_enabled.pptx", SaveFormat.Pptx);

    seriesGroup.setSeriesLines(false);
    presentation.save("series_lines_disabled.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}
系列線條啟用 系列線條關閉
Pie of Pie chart with series lines enabled Pie of Pie chart with series lines disabled
兩條線條將主圓餅連接至次圓餅。 兩個圓餅仍可見,但連接線已隱藏。

系列線條不同於資料標籤指示線(將標籤連接至資料點的線條)、格線(在座標軸上標示間隔的線條)以及折線圖中的線條(表示資料值)。此設定不會控制上述元素。

常見問題

哪些圖表類型支援資料系列?

所有由 ChartType 列舉的圖表類型皆使用圖表資料,但其系列的值結構或設定並不完全相同。例如,類別圖表使用類別與值,散佈圖使用 X 與 Y 值,氣泡圖則額外使用氣泡大小。請使用與系列類型相符的資料點建立方法。重疊與間隙寬度等選項僅適用於相容的長條或柱狀群組。

什麼是圖表系列群組?

IChartSeriesGroup 包含共享群組層級繪製設定的相容系列。組合圖表可能包含多個群組,因此透過某個系列取得的群組設定不一定會影響圖表中所有系列。

新建立的圖表是否包含預設資料?

是。預設情況下,IShapeCollection.addChart 會建立範例系列、類別與數值。您可以編輯這些儲存格,或在加入完全自訂的資料集前先清除系列與類別集合。亦可使用其他覆載方法建立不含預設資料的圖表。

圖表物件如何連結至工作簿儲存格?

系列名稱、類別標籤與資料點值皆參照 IChartDataWorkbook 中的儲存格。變更參照的儲存格會更新相應的圖表元素。自行建構資料時,請保持類別列與系列值列對齊,以確保每個點繪製於正確的類別下。

如何只清除單一點而非整個系列?

將相關的值儲存格設為 null,即可保留該點的類別位置作為空白點。僅在需要移除整個系列所有點時,才使用 IChartDataPointCollection.clear,因為該方法會移除該系列中的所有資料點。

空白點如何顯示?

結果取決於圖表類型與透過 IChart.setDisplayBlanksAs 設定的值。受支援的圖表可將空白顯示為間隙、零值或連接相鄰點。請選擇符合您簡報中缺失資料意義的設定。詳情請參閱 控制空白儲存格的顯示 中的完整範例與視覺比較。

負值的格式如何設定?

對於受支援的長條、柱狀與氣泡系列,請呼叫 IChartSeries.setInvertIfNegative 並設定由 IChartSeries.getInvertedSolidFillColor 回傳的色彩。您也可以透過 IChartDataPoint.setInvertIfNegative 為單一點覆寫此行為。這些方法影響的是格式,而非儲存的數值。

當系列與資料點同時設定格式時,哪一個優先?

明確的資料點格式會優先套用於該點。其他點仍會使用明確的系列格式,或在系列格式未定義時使用自動圖表樣式與佈景主題。群組設定如重疊與間隙寬度屬於版面配置,並非資料點層級的格式覆寫。

圖表的系列數量有上限嗎?

Aspose.Slides 本身未設定固定的系列數量上限。實務上,簡報檔案的限制、可用記憶體、渲染時間與圖表可讀性會決定實際可用的上限。

當柱狀或長條過於靠近或過於分離時,應如何調整?

對適當的父系列群組呼叫 IChartSeriesGroup.setGapWidth。增加數值可擴大叢集之間的間距,減少數值則使叢集更緊密。