Chart

aspose-cells-foss รองรับการฝังแผนภูมิในแผ่นงาน. แผนภูมิจะถูกจัดการผ่าน ws.charts, a ChartCollection แนบกับแต่ละ Worksheet. ข้อมูลซีรีส์ถูกเพิ่มผ่าน chart.n_series, หนึ่ง NSeries คอลเลกชัน.

Properties: aspose.cells_foss

from aspose.cells_foss import ChartType

ChartType

ChartType เป็น IntEnum ที่ระบุประเภทแผนภูมิ.

NameTypeAccessDescription
type``ReadGets the type.
title``Read/WriteGets or sets the title.
category_data``Read/WriteGets or sets the category data.
show_legend``Read/WriteGets or sets the show legend.
legend_position``Read/WriteGets or sets the legend position.
smooth``Read/WriteGets or sets the smooth.
n_series``ReadGets the n series.
NSeries``ReadPascalCase alias of n_series.
grouping``Read/WriteGets or sets the grouping.
bar_direction``Read/WriteGets or sets the bar direction.
gap_width``Read/WriteGets or sets the gap width.
overlap``Read/WriteGets or sets the overlap.
vary_colors``Read/WriteGets or sets the vary colors.
first_slice_angle``Read/WriteGets or sets the first slice angle.
is_of_pie``Read/WriteGets or sets the is of pie.
of_pie_type``Read/WriteGets or sets the of pie type.
second_pie_size``Read/WriteGets or sets the second pie size.
quartile_method``Read/WriteGets or sets the quartile method.
box_show_mean_line``Read/WriteGets or sets the box show mean line.
box_show_mean_marker``Read/WriteGets or sets the box show mean marker.
box_show_inner_points``Read/WriteGets or sets the box show inner points.
box_show_outlier_points``Read/WriteGets or sets the box show outlier points.
box_gap_width``Read/WriteGets or sets the box gap width.
is_3d``Read/WriteGets or sets the is 3d.
gap_depth``Read/WriteGets or sets the gap depth.
view_3d``ReadGets the view 3d.
View3D``ReadPascalCase alias of view_3d.
show_connector_lines``Read/WriteGets or sets the show connector lines.
has_subtotals``Read/WriteGets or sets the has subtotals.
sub_charts``ReadList of sub-chart descriptors for combo charts.
axes``ReadList of ChartAxis objects defining all axes for the chart.
scatter_style``Read/WriteGets or sets the scatter style.
wireframe``Read/WriteWhether the surface chart uses wireframe display mode (<c:wireframe val=‘1’/>).
radar_style``Read/WriteRadar chart style: ‘standard’, ‘marker’, or ‘filled’.
histogram_bin_count``Read/WriteNumber of bins for count-based binning (int or None for auto/size-based).
histogram_bin_size``Read/WriteBin width for size-based binning (float or None for auto/count-based).
histogram_interval_closed``Read/WriteWhich side of each bin interval is closed: ‘r’ (right) or ’l’ (left).
histogram_overflow``Read/WriteOverflow bin boundary value (float or None).
histogram_underflow``Read/WriteUnderflow bin boundary value (float or None).
disp_blanks_as``Read/WriteGets or sets the disp blanks as.
stock_style``Read/WriteGets or sets the stock style.

Properties

Chart อ็อบเจ็กต์ไม่ถูกสร้างโดยตรง. ใช้ ws.charts.add(...) หรือเมธอดสะดวกแบบพิมพ์ (add_bar(), add_line(), add_pie(), add_area()).

Properties

SignatureDescription
__init__(chart_type, upper_left_row, upper_left_column, lower_right_row, lower_right_column)
add_series(values, category_data, name, chart_type, x_values)Convenience method to add a series.
add_axis(axis_type, axis_id)Adds an axis to the chart and returns it.
copy()Creates and returns a duplicate of the chart

ChartCollection

ChartCollection เข้าถึงได้เป็น ws.charts. มีแผนภูมิทั้งหมดที่ฝังอยู่ในแผนงานหนึ่ง.

Properties

add

ws.charts.add(
    chart_type: ChartType,
    upper_left_row: int,
    upper_left_column: int,
    lower_right_row: int,
    lower_right_column: int
) -> Chart

เพิ่มแผนภูมิประเภทที่ระบุ. ทุกอาร์กิวเมนต์ตำแหน่งใช้ดัชนีแถว/คอลัมน์เริ่มจาก 0.

add_bar

ws.charts.add_bar(upper_left_row, upper_left_column, lower_right_row, lower_right_column) -> Chart

ทางลัดสำหรับ add(ChartType.BAR, ...).

add_line

ws.charts.add_line(upper_left_row, upper_left_column, lower_right_row, lower_right_column) -> Chart

ทางลัดสำหรับ add(ChartType.LINE, ...).

add_pie

ws.charts.add_pie(upper_left_row, upper_left_column, lower_right_row, lower_right_column) -> Chart

ทางลัดสำหรับ add(ChartType.PIE, ...).

add_area

ws.charts.add_area(upper_left_row, upper_left_column, lower_right_row, lower_right_column) -> Chart

ทางลัดสำหรับ add(ChartType.AREA, ...).

คุณสมบัติและการวนซ้ำ


NSeries

NSeries เข้าถึงได้ผ่าน chart.n_series. มันจัดการชุดข้อมูลที่เป็นของแผนภูมิ.

Properties

add

chart.n_series.add(
    area: str,
    is_vertical: bool = False,
    category_data: str | None = None,
    name: str | None = None,
    chart_type: ChartType | None = None
) -> ChartSeries

เพิ่มชุดข้อมูล. area เป็นสตริงช่วงเช่น "Sheet1!B1:B5". ตั้งค่า is_vertical=True เมื่อข้อมูลจัดเรียงเป็นคอลัมน์. chart_type แทนที่ประเภทแผนภูมิแม่สำหรับชุดนี้ (ใช้ในแผนภูมิแบบคอมโบ).

คุณสมบัติและการวนซ้ำ


ChartSeries

ChartSeries แสดงถึงชุดข้อมูลเดียวภายในแผนภูมิ ได้รับผ่าน chart.n_series[index].

Properties

Properties

add_error_bars

series.add_error_bars(
    direction='y',
    bar_type='both',
    val_type='fixedVal',
    val=1.0,
    no_end_cap=False
) -> ChartErrorBars

เพิ่มแถบความผิดพลาดให้กับชุดข้อมูลนี้และคืนค่า ChartErrorBars อ็อบเจกต์.


ChartAxis

ChartAxis เข้าถึงได้ผ่าน chart.axes[index].

Properties


ChartView3D

ChartView3D เข้าถึงได้ผ่าน chart.view_3d. ใช้ได้เฉพาะเมื่อ chart.is_3d คือ True.

Properties


ChartErrorBars

ChartErrorBars เข้าถึงได้ผ่าน series.error_bars. สร้างด้วย series.add_error_bars(...).

Properties


Properties

ตัวอย่างต่อไปนี้เขียนข้อมูลรายได้รายเดือน, สร้างแผนภูมิแท่งแบบกลุ่มพร้อมหัวเรื่องและสองชุดข้อมูล, และบันทึกเวิร์กบุ๊ก.

from aspose.cells_foss import Workbook, ChartType

wb = Workbook()
ws = wb.worksheets[0]
ws.name = "Revenue"

# Write headers and data
headers = ["Month", "Product A", "Product B"]
data = [
    ["Jan", 12000, 9500],
    ["Feb", 14500, 11000],
    ["Mar", 13200, 12800],
    ["Apr", 15800, 14100],
]
for col, h in enumerate(headers):
    ws.cells[0][col].put_value(h)
for row, row_data in enumerate(data, start=1):
    for col, val in enumerate(row_data):
        ws.cells[row][col].put_value(val)

# Add a bar chart covering rows 6-20, columns 0-6
chart = ws.charts.add_bar(6, 0, 20, 6)
chart.title = "Monthly Revenue by Product"
chart.bar_direction = "col"   # vertical (column chart)
chart.grouping = "clustered"

# Series: Product A and Product B
chart.n_series.add("Revenue!B2:B5", is_vertical=True, category_data="Revenue!A2:A5", name="Product A")
chart.n_series.add("Revenue!C2:C5", is_vertical=True, category_data="Revenue!A2:A5", name="Product B")

chart.show_legend = True
chart.legend_position = "bottom"

wb.save("revenue_chart.xlsx")

ดูเพิ่มเติม

 ภาษาไทย