สร้างแผนภูมิในงานนำเสนอ PPTX ด้วย C++
สร้างแผนภูมิในงานนำเสนอ PPTX ด้วย API ฝั่งเซิร์ฟเวอร์ของ Aspose.Slides for C++ โดยไม่ต้องใช้ Microsoft PowerPoint
สร้างแผนภูมิ PPTX ด้วย C++
ใช้ Aspose.Slides for C++ เพื่อสร้างแผนภูมิในงานนำเสนอ PPTX ติดตั้งแพ็กเกจจาก NuGet หรือใช้คำสั่งต่อไปนี้ใน Package Manager Console
คำสั่ง
PM> Install-Package Aspose.Slides.Cppสร้างแผนภูมิใน PPTX – C++
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
// Add a chart with default data.
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 0, 0, 500, 500);
// Set the index of the chart data sheet.
int defaultWorksheetIndex = 0;
// Get the chart data workbook.
auto chartDataWorkbook = chart->get_ChartData()->get_ChartDataWorkbook();
// Set the chart title.
chart->get_ChartTitle()->AddTextFrameForOverriding(u"Sample Title");
chart->get_ChartTitle()->get_TextFrameForOverriding()->get_TextFrameFormat()->set_CenterText(NullableBool::True);
chart->get_ChartTitle()->set_Height(20);
chart->set_HasTitle(true);
// Delete the default generated series and categories.
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
// Add series.
chart->get_ChartData()->get_Series()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box(String(u"Series 1"))), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 0, 2, ObjectExt::Box(String(u"Series 2"))), chart->get_Type());
// Add categories.
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box(String(u"Category 1"))));
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box(String(u"Category 2"))));
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box(String(u"Category 3"))));
// Take the first chart series.
auto series = chart->get_ChartData()->get_Series()->idx_get(0);
// Populate series data.
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box(20)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box(50)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box(30)));
// Set the fill color for the series.
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(Color::get_Blue());
// Take the second chart series.
series = chart->get_ChartData()->get_Series()->idx_get(1);
// Populate series data.
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 2, ObjectExt::Box(30)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 2, ObjectExt::Box(10)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 2, ObjectExt::Box(60)));
// Set the fill color for the series.
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(Color::get_Orange());
// Show the category name for the first label.
auto dataLabel = series->get_DataPoints()->idx_get(0)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowCategoryName(true);
dataLabel = series->get_DataPoints()->idx_get(1)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowSeriesName(true);
// Show the value for the third label.
dataLabel = series->get_DataPoints()->idx_get(2)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowValue(true);
dataLabel->get_DataLabelFormat()->set_ShowSeriesName(true);
dataLabel->get_DataLabelFormat()->set_Separator(u"/");
// Save the PPTX file.
presentation->Save(u"column_chart.pptx", SaveFormat::Pptx);
presentation->Dispose();วิธีสร้างแผนภูมิในไฟล์ PPTX ด้วย C++
สร้างแผนภูมิในงานนำเสนอ PPTX ด้วย Aspose.Slides for C++ ด้วยโค้ดเพียงไม่กี่บรรทัด
- สร้างออบเจ็กต์
Presentation - เข้าถึงสไลด์แรก
- เพิ่มแผนภูมิพร้อมข้อมูลเริ่มต้น
- ตั้งค่าดัชนีของแผ่นข้อมูลแผนภูมิ
- รับเวิร์กบุ๊กข้อมูลของแผนภูมิ
- ตั้งชื่อแผนภูมิ
- ลบชุดข้อมูลและหมวดหมู่ที่สร้างขึ้นตามค่าเริ่มต้น
- เพิ่มชุดข้อมูลและหมวดหมู่
- นำชุดข้อมูลแรกของแผนภูมิมาเติมข้อมูล
- ตั้งค่าสีเติมของชุดข้อมูล
- แสดงชื่อหมวดหมู่ ชื่อชุดข้อมูล และค่าในป้ายชื่อข้อมูลของชุดข้อมูลที่สอง
- บันทึกไฟล์ PPTX
ความต้องการของระบบ
Aspose.Slides for C++ รองรับแพลตฟอร์มและระบบปฏิบัติการหลัก ตรวจสอบให้แน่ใจว่าสภาพแวดล้อมของคุณเป็นไปตามข้อกำหนดเบื้องต้นต่อไปนี้
- Microsoft Windows, Linux, macOS หรือระบบปฏิบัติการอื่นที่เข้ากันได้ซึ่งมีรันไทม์ C++ ที่รองรับ
- ไลบรารี Aspose.Slides for C++ ที่อ้างอิงในโปรเจกต์ของคุณ
สร้างด้วย Aspose.Slides
สร้างแผนภูมิ PPTX ออนไลน์
แอป Aspose.Slides Chart ฟรีนี้สร้างด้วย Aspose.Slides for C++ ซึ่งเป็น API เดียวกับโค้ดด้านบน เปิดแอปแล้วดูว่า API ทำอะไรได้บ้างกับไฟล์ PPTX ของคุณเอง
- ทำงานในเบราว์เซอร์ ไม่ต้องติดตั้งสิ่งใด
- ดูว่า Aspose.Slides สร้างแผนภูมิอย่างไรก่อนเขียนโค้ด
- สร้างแผนภูมิจากข้อมูล Excel หรือข้อมูลในตาราง
- ดาวน์โหลดเป็นไฟล์ PPTX หรือรูปภาพ
PPTX รูปแบบไฟล์คืออะไร
ไฟล์ PPTX คือไฟล์งานนำเสนอที่สร้างด้วย Microsoft PowerPoint และแอปงานนำเสนออื่นๆ ต่างจากรูปแบบไบนารี PPT แบบเก่า PPTX ใช้ Office Open XML งานนำเสนอประกอบด้วยสไลด์ที่อาจมีข้อความ รูปภาพ การจัดรูปแบบ ภาพเคลื่อนไหว และสื่ออื่นๆ สไลด์จะแสดงต่อผู้ชมเป็นการนำเสนอสไลด์ด้วยการตั้งค่าที่กำหนดเอง
รูปแบบอื่นที่รองรับสำหรับแผนภูมิ
ด้วย C++ คุณยังสร้างแผนภูมิในรูปแบบอื่นได้ด้วย