Quickstart

เริ่มต้นอย่างเร็ว

หน้านี้มีตัวอย่างอิสระสองตัวอย่างที่คุณสามารถคัดลอกไปยังโครงการคอนโซล .NET (หลังจาก สร้างไลบรารีจากซอร์สโค้ด) และรันได้ทันที.


ตัวอย่างที่ 1 — สร้างเอกสารพร้อมแผนภูมิเส้น

สร้างเอกสารใหม่, แทรกแผนภูมิเส้นด้วย DocumentBuilder.InsertChart(), ล้างซีรีส์เริ่มต้น, และเพิ่มข้อมูลของคุณเอง:

using Aspose.Words;
using Aspose.Words.Drawing.Charts;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Line, 432, 252);
Chart chart = shape.Chart;

// Delete default generated series.
chart.Series.Clear();

string[] categories = new string[] { "AW Category 1", "AW Category 2", "AW Category 3" };
chart.Series.Add("AW Series 1", categories, new double[] { 4.3, 2.5, 3.5 });

doc.Save("chart.docx");

ตัวอย่างที่ 2 — กำหนดค่าแผนภูมิวงกลมด้วยป้ายข้อมูล

แทรกแผนภูมิวงกลม, เพิ่มซีรีส์, และกำหนดค่า ChartDataLabelCollection ให้แสดงเปอร์เซ็นต์และค่า:

using Aspose.Words;
using Aspose.Words.Drawing.Charts;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Pie, 432, 252);
Chart chart = shape.Chart;
chart.Series.Clear();

ChartSeries series = chart.Series.Add("Series 1",
    new string[] { "Category1", "Category2", "Category3" },
    new double[] { 2.7, 3.2, 0.8 });

ChartDataLabelCollection labels = series.DataLabels;
labels.ShowPercentage = true;
labels.ShowValue = true;
labels.ShowLeaderLines = false;
labels.Separator = " - ";

doc.Save("pie-chart.docx");

ChartSeries.Add() รับชื่อหมวดหมู่พร้อมกับค่าต่าง ๆ, และ ChartDataLabelCollection ควบคุมว่าป้ายข้อมูลแต่ละอันจะแสดงอะไร — เปอร์เซ็นต์, ค่า, ชื่อหมวดหมู่, หรือการรวมกันที่คั่นด้วย Separator.


ขั้นตอนต่อไป

ดูเพิ่มเติม

 ภาษาไทย