• <menu id="w2i4a"></menu>
  • logo Aspose.Words使用教程

    文檔首頁>>Aspose.Words使用教程>>Aspose.Words for C++使用教程:從Scratch創(chuàng)建OOXML圖表(上)

    Aspose.Words for C++使用教程:從Scratch創(chuàng)建OOXML圖表(上)


    Aspose.Words for C++不依賴Microsoft Word,可在任何C++應(yīng)用程序中生成和操作Word格式文檔。本文將與大家分享如何插入柱形圖到文檔中。

    下載Aspose.Words for C++最新試用版

    Aspose.Words for C++提供了 InsertChart 方法,該方法已添加到 DocumentBuilder 類中。那么,讓我們看看如何使用 DocumentBuilder-> InsertChart 方法將簡單的柱形圖插入到文檔中:

    如何插入柱形圖。

    下面的示例代碼顯示了如何插入柱形圖。

    System::SharedPtr<Document> doc = System::MakeObject<Document>();
    System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc);
    
    // Add chart with default data. You can specify different chart types and sizes.
    System::SharedPtr<Shape> shape = builder->InsertChart(ChartType::Column, 432, 252);
    
    // Chart property of Shape contains all chart related options.
    System::SharedPtr<Chart> chart = shape->get_Chart();
    
    // Get chart series collection.
    System::SharedPtr<ChartSeriesCollection> seriesColl = chart->get_Series();
    // Check series count.
    std::cout << seriesColl->get_Count() << std::endl;
    
    // Delete default generated series.
    seriesColl->Clear();
    
    // Create category names array, in this example we have two categories.
    System::ArrayPtr<System::String> categories = System::MakeArray<System::String>({u"AW Category 1", u"AW Category 2"});
    
    // Adding new series. Please note, data arrays must not be empty and arrays must be the same size.
    seriesColl->Add(u"AW Series 1", categories, System::MakeArray<double>({1, 2}));
    seriesColl->Add(u"AW Series 2", categories, System::MakeArray<double>({3, 4}));
    seriesColl->Add(u"AW Series 3", categories, System::MakeArray<double>({5, 6}));
    seriesColl->Add(u"AW Series 4", categories, System::MakeArray<double>({7, 8}));
    seriesColl->Add(u"AW Series 5", categories, System::MakeArray<double>({9, 10}));
    
    System::String outputPath = dataDir + GetOutputFilePath(u"CreateColumnChart.InsertSimpleColumnChart.doc");
    doc->Save(outputPath);

    該代碼會(huì)產(chǎn)生以下結(jié)果:

    插入柱形圖

    Add系列方法有四種不同的重載,它們涵蓋了所有圖表類型的所有可能的數(shù)據(jù)源變體:

    System::SharedPtr<Document> doc = System::MakeObject<Document>();
    System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc);
    
    // Insert Column chart.
    System::SharedPtr<Shape> shape = builder->InsertChart(ChartType::Column, 432, 252);
    System::SharedPtr<Chart> chart = shape->get_Chart();
    
    // Use this overload to add series to any type of Bar, Column, Line and Surface charts.
    chart->get_Series()->Add(u"AW Series 1", System::MakeArray<System::String>({u"AW Category 1", u"AW Category 2"}), System::MakeArray<double>({1, 2}));
    
    System::String outputPath = dataDir + GetOutputFilePath(u"CreateColumnChart.InsertColumnChart.doc");
    doc->Save(outputPath);

    該代碼會(huì)產(chǎn)生以下結(jié)果:

    插入柱形圖02

    下一篇文章將教大家如何插入面積圖、氣泡圖等。如果你有任何問題或意見,歡迎在下方評(píng)論區(qū)留言~

    為你推薦:Aspose專題 - Aspose最新資源合集


    想要購買正版授權(quán),或者獲取更多Aspose.Words for C++相關(guān)信息的朋友可以點(diǎn)擊" 咨詢在線客服 "~
    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();