Tạo biểu đồ trong bản trình bày PPT bằng C++
Tạo biểu đồ trong bản trình bày PPT bằng API phía máy chủ của Aspose.Slides for C++ mà không cần Microsoft PowerPoint.
Tạo biểu đồ PPT bằng C++
Dùng Aspose.Slides for C++ để tạo biểu đồ trong bản trình bày PPT. Cài đặt gói từ NuGet hoặc dùng lệnh sau trong Package Manager Console.
Lệnh
PM> Install-Package Aspose.Slides.CppTạo biểu đồ trong PPT – 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 PPT file.
presentation->Save(u"column_chart.ppt", SaveFormat::Ppt);
presentation->Dispose();Cách tạo biểu đồ trong tệp PPT bằng C++
Tạo biểu đồ trong bản trình bày PPT với Aspose.Slides for C++ chỉ bằng vài dòng mã.
- Tạo một đối tượng
Presentation. - Truy cập trang chiếu đầu tiên.
- Thêm biểu đồ với dữ liệu mặc định.
- Đặt chỉ mục của trang dữ liệu biểu đồ.
- Lấy sổ làm việc dữ liệu biểu đồ.
- Đặt tiêu đề biểu đồ.
- Xóa các chuỗi dữ liệu và danh mục được tạo mặc định.
- Thêm chuỗi dữ liệu và danh mục.
- Lấy chuỗi đầu tiên của biểu đồ và điền dữ liệu cho chuỗi.
- Đặt màu tô cho chuỗi.
- Hiển thị tên danh mục, tên chuỗi và giá trị trong nhãn dữ liệu của chuỗi thứ hai.
- Lưu tệp PPT.
Yêu cầu hệ thống
Aspose.Slides for C++ hỗ trợ các nền tảng và hệ điều hành chính. Hãy đảm bảo môi trường của bạn đáp ứng các điều kiện tiên quyết sau.
- Microsoft Windows, Linux, macOS hoặc hệ điều hành tương thích khác có môi trường chạy C++ được hỗ trợ.
- Thư viện Aspose.Slides for C++ được tham chiếu trong dự án của bạn.
Được xây dựng bằng Aspose.Slides
Tạo biểu đồ PPT trực tuyến
Ứng dụng Aspose.Slides Chart miễn phí được xây dựng bằng Aspose.Slides for C++, cùng API với đoạn mã ở trên. Hãy mở ứng dụng và xem API có thể làm gì với các tệp PPT của riêng bạn.
- Chạy trong trình duyệt, không cần cài đặt gì.
- Xem cách Aspose.Slides tạo biểu đồ trước khi bạn viết mã.
- Tạo biểu đồ từ dữ liệu Excel hoặc bảng.
- Tải xuống dưới dạng tệp PPT hoặc hình ảnh.
Những gì là PPT Tập Tin Định Dạng
Tệp PPT chứa một tập hợp trang chiếu cho buổi trình chiếu. Tệp dùng định dạng tệp nhị phân của Microsoft PowerPoint 97-2003. Tệp PPT có thể chứa văn bản, dấu đầu dòng, hình ảnh, đa phương tiện và các đối tượng OLE nhúng khác. Microsoft giới thiệu định dạng PPTX mới hơn trong PowerPoint 2007. PPTX dựa trên Office Open XML và khác với định dạng nhị phân cũ hơn. Các ứng dụng khác như OpenOffice Impress và Apple Keynote cũng có thể tạo tệp PPT.
Các định dạng khác được hỗ trợ cho biểu đồ
Với C++, bạn cũng có thể tạo biểu đồ ở các định dạng khác.