Sparkline
Sparklines adalah diagram miniatur yang disematkan dalam sel individual, diperkenalkan di Excel 2010. aspose-cells-foss mengelola sparklines melalui SparklineGroup dan SparklineGroupCollection (ws.sparkline_groups). Setiap grup berisi satu atau lebih Sparkline objek yang berbagi tipe dan pengaturan warna yang sama.
ImageRenderOptions: aspose.cells_foss
from aspose.cells_foss import SparklineType, SparklineEmptyCells, Sparkline, SparklineGroupSparklineType
SparklineType adalah sebuah IntEnum yang mengidentifikasi bentuk visual dari grup sparkline.
| Name | Type | Access | Description |
|---|---|---|---|
data_range | `` | Read | Gets the data range. |
cell_reference | `` | Read | Gets the cell reference. |
SparklineEmptyCells
SparklineEmptyCells adalah sebuah IntEnum yang mengontrol bagaimana sel kosong ditangani dalam sparkline.
| Signature | Description |
|---|---|
__init__(data_range: str, cell_reference: str) | |
copy() | Creates and returns a duplicate of this Sparkline object |
ImageRenderOptions
Sebuah Sparkline mengikat satu rentang data ke satu lokasi sel.
ImageRenderOptions
Sparkline(data_range: str, cell_reference: str)ImageRenderOptions
SparklineGroup
A SparklineGroup menentukan pengaturan visual bersama (tipe, warna, penanganan sel kosong) untuk sekumpulan sparkline. SparklineGroup objek tidak dibangun secara langsung — gunakan ws.sparkline_groups.add(...) atau ws.sparkline_groups.add_group(...).
ImageRenderOptions
ImageRenderOptions
add_sparkline
group.add_sparkline(data_range: str, cell_reference: str) -> SparklineMenambahkan sparkline individu ke grup ini dan mengembalikan yang baru Sparkline objek.
SparklineGroupCollection
SparklineGroupCollection diakses sebagai ws.sparkline_groups. Ini berisi semua grup sparkline pada lembar kerja.
ImageRenderOptions
add
ws.sparkline_groups.add(
sparkline_type=SparklineType.LINE,
data_range=None,
is_vertical=False,
location_range=None
) -> SparklineGroupMembuat grup baru dan secara opsional mengisinya dengan sparkline yang dihasilkan dari data_range (baris atau kolom tergantung pada is_vertical) ditempatkan ke sel yang dijelaskan oleh location_range. Mengembalikan yang baru SparklineGroup.
add_group
ws.sparkline_groups.add_group(sparkline_type=SparklineType.LINE) -> SparklineGroupMembuat grup kosong dengan tipe yang diberikan. Sparkline harus ditambahkan secara individual dengan group.add_sparkline(...).
Properti dan Iterasi
ImageRenderOptions
Contoh berikut menulis data pendapatan bulanan untuk tiga wilayah dan menambahkan sparkline garis untuk setiap baris.
from aspose.cells_foss import Workbook, SparklineType, SparklineEmptyCells
wb = Workbook()
ws = wb.worksheets[0]
ws.name = "Trends"
# Write headers
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
for col, m in enumerate(months):
ws.cells[0][col + 1].put_value(m)
ws.cells["A1"].put_value("Region")
ws.cells["H1"].put_value("Trend")
# Write three rows of data
regions = [
("North", [12000, 14500, 13800, 16200, 15900, 17400]),
("South", [9800, 10200, 11500, 10900, 12300, 13100]),
("West", [7500, 8100, 7900, 8800, 9200, 10500]),
]
for row_i, (name, values) in enumerate(regions, start=1):
ws.cells[row_i][0].put_value(name)
for col_i, v in enumerate(values):
ws.cells[row_i][col_i + 1].put_value(v)
# Add a line sparkline group — one sparkline per data row
group = ws.sparkline_groups.add(
sparkline_type=SparklineType.LINE,
data_range="Trends!B2:G4",
is_vertical=False,
location_range="Trends!H2:H4",
)
# Customize colors
group.color_series = "4472C4" # blue lines
group.color_high = "70AD47" # green for peak
group.color_low = "FF0000" # red for trough
group.display_empty_cells_as = SparklineEmptyCells.GAP
wb.save("sparklines.xlsx")