PowerPoint प्रस्तुति चार्ट बनाएँ या अपडेट करें C++
अवलोकन
यह लेख Aspose.Slides का उपयोग करके चार्ट बनाने और अनुकूलित करने के लिए एक व्यापक मार्गदर्शिका प्रदान करता है। आप सीखेंगे कि प्रोग्रामेटिक तौर पर स्लाइड में चार्ट कैसे जोड़ें, डेटा से भरें, और विभिन्न फ़ॉर्मेटिंग विकल्प लागू करके अपनी विशिष्ट डिज़ाइन आवश्यकताओं को पूरा करें। पूरे लेख में विस्तृत कोड उदाहरण प्रत्येक चरण को दर्शाते हैं, प्रस्तुति और चार्ट ऑब्जेक्ट को इनिशियलाइज़ करने से लेकर सीरीज़, अक्ष और लेजेंड को कॉन्फ़िगर करने तक। इस मार्गदर्शिका का पालन करके आप अपने अनुप्रयोगों में डायनेमिक चार्ट जनरेशन को एकीकृत करने की ठोस समझ प्राप्त करेंगे, जिससे डेटा‑चालित प्रस्तुतियों को बनाना आसान हो जाएगा।
चार्ट बनाना
चार्ट डेटा को जल्दी से विज़ुअलाइज़ करने और ऐसे अंतर्दृष्टि निकालने में मदद करते हैं, जो तालिका या स्प्रेडशीट से तुरंत स्पष्ट नहीं होते।
चार्ट क्यों बनाएं?
चार्ट का उपयोग करके आप
- बड़ी मात्रा में डेटा को एक ही स्लाइड में समेकित, संक्षिप्त या सारांशित कर सकते हैं
- डेटा में पैटर्न और ट्रेंड को उजागर कर सकते हैं
- समय के साथ या किसी विशिष्ट माप इकाई के सापेक्ष डेटा की दिशा और गति का अनुमान लगा सकते हैं
- अपवाद, विचलन, त्रुटियां, असंगत डेटा आदि की पहचान कर सकते हैं
- जटिल डेटा को प्रभावी ढंग से संप्रेषित या प्रस्तुत कर सकते हैं
PowerPoint में, आप इंसर्ट फ़ंक्शन के माध्यम से विभिन्न प्रकार के चार्ट टेम्प्लेट चुनकर चार्ट बना सकते हैं। Aspose.Slides का उपयोग करके आप सामान्य चार्ट (लोकप्रिय चार्ट प्रकारों पर आधारित) और कस्टम चार्ट दोनों बना सकते हैं।
सामान्य चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डेटा के साथ एक चार्ट जोड़ें और अपनी वांछित चार्ट प्रकार निर्दिष्ट करें।
- चार्ट के लिए एक शीर्षक जोड़ें।
- चार्ट डेटा कार्यपत्रक तक पहुँचें।
- सभी डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- चार्ट सीरीज़ के लिए नई डेटा जोड़ें।
- चार्ट सीरीज़ के लिए भराव रंग जोड़ें।
- चार्ट सीरीज़ के लिए लेबल जोड़ें।
- संशोधित प्रस्तुति को PPTX फ़ाइल के रूप में लिखें।
यह C++ कोड दिखाता है कि सामान्य चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ।
const String outPath = u"../out/NormalCharts_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली प्रस्तुति क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// डिफ़ॉल्ट डेटा के साथ चार्ट जोड़ता है
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::ClusteredColumn, 0, 0, 500, 500);
// चार्ट डेटा शीट का इंडेक्स सेट करता है
int defaultWorksheetIndex = 0;
// चार्ट डेटा कार्यपत्रक प्राप्त करता है
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// चार्ट शीर्षक सेट करता है
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);
// डिफ़ॉल्ट जनरेटेड सीरीज़ और श्रेणियों को हटाता है
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
int s = chart->get_ChartData()->get_Series()->get_Count();
s = chart->get_ChartData()->get_Categories()->get_Count();
// नई सीरीज़ जोड़ता है
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 2, ObjectExt::Box<System::String>(u"Series 2")), chart->get_Type());
// श्रेणियाँ जोड़ता है
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box<System::String>(u"Caetegoty 1")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box<System::String>(u"Caetegoty 2")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box<System::String>(u"Caetegoty 3")));
// पहली चार्ट सीरीज़ लेता है
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);
// सीरीज़ डेटा भरता है
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<double>(20)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(50)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(30)));
// सीरीज़ के लिए भराव रंग सेट करता है
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red());
// दूसरी चार्ट सीरीज़ लेता है
series = chart->get_ChartData()->get_Series()->idx_get(1);
// सीरीज़ डेटा भरता है
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 1, 2, ObjectExt::Box<double>(30)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 2, 2, ObjectExt::Box<double>(10)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 3, 2, ObjectExt::Box<double>(60)));
// सीरीज़ के लिए भराव रंग सेट करता है
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Green());
// पहली लेबल को श्रेणी नाम दिखाने के लिए सेट करता है
SharedPtr<IDataLabel> lbl = series->get_DataPoints()->idx_get(0)->get_Label();
lbl->get_DataLabelFormat()->set_ShowCategoryName(true);
lbl = series->get_DataPoints()->idx_get(1)->get_Label();
lbl->get_DataLabelFormat()->set_ShowSeriesName (true);
// तीसरी लेबल के लिए मान दिखाता है
lbl = series->get_DataPoints()->idx_get(2)->get_Label();
lbl->get_DataLabelFormat()->set_ShowValue (true);
lbl->get_DataLabelFormat()->set_ShowSeriesName(true);
lbl->get_DataLabelFormat()->set_Separator (u"/");
// प्रस्तुति सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
स्कैटर्ड चार्ट बनाएं
स्कैटर्ड चार्ट (जिसे स्कैटर प्लॉट या x‑y ग्राफ़ भी कहा जाता है) अक्सर दो वेरिएबल के बीच पैटर्न या सहसंबंध की जाँच करने के लिए उपयोग किए जाते हैं।
आप स्कैटर्ड चार्ट तब उपयोग करना चाह सकते हैं जब
- आपके पास युग्मित संख्यात्मक डेटा हो
- दो वेरिएबल एक साथ अच्छी तरह से जुड़ते हों
- आप यह निर्धारित करना चाहें कि दो वेरिएबल संबंधित हैं या नहीं
- एक स्वतंत्र वेरिएबल के कई मान हों जो निर्भर वेरिएबल के लिए हों
यह C++ कोड दिखाता है कि विभिन्न मार्कर सीरीज़ के साथ स्कैटर्ड चार्ट कैसे बनाया जाए:
// दस्तावेज़ निर्देशिका का पथ।
const String outPath = u"../out/ScatteredChart_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली प्रस्तुति क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// डिफ़ॉल्ट डेटा के साथ चार्ट जोड़ता है
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::ScatterWithSmoothLines, 0, 0, 500, 500);
// चार्ट शीर्षक सेट करता है
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);
// डिफ़ॉल्ट जनरेटेड सीरीज़ को हटाता है
chart->get_ChartData()->get_Series()->Clear();
// चार्ट डेटा शीट के लिए इंडेक्स सेट करता है
int defaultWorksheetIndex = 0;
// चार्ट डेटा कार्यपत्रक प्राप्त करता है
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// नई सीरीज़ जोड़ता है
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 1, 3, ObjectExt::Box<System::String>(u"Series 2")), chart->get_Type());
// पहली चार्ट सीरीज़ लेता है
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);
// नया बिंदु जोड़ता है (1:3)
series->get_DataPoints()->AddDataPointForScatterSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(1)), fact->GetCell(defaultWorksheetIndex, 2, 2, ObjectExt::Box<double>(3)));
// नया बिंदु जोड़ता है (2:10)
series->get_DataPoints()->AddDataPointForScatterSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(2)), fact->GetCell(defaultWorksheetIndex, 3, 2, ObjectExt::Box<double>(10)));
// सीरीज़ प्रकार संपादित करता है
series->set_Type (ChartType::ScatterWithStraightLinesAndMarkers);
// चार्ट सीरीज़ मार्कर बदलता है
series->get_Marker()->set_Size (10);
series->get_Marker()->set_Symbol(MarkerStyleType::Star);
// दूसरी चार्ट सीरीज़ लेता है
series = chart->get_ChartData()->get_Series()->idx_get(1);
// नया बिंदु जोड़ता है (5:2)
series->get_DataPoints()->AddDataPointForScatterSeries(fact->GetCell(defaultWorksheetIndex, 2, 3, ObjectExt::Box<double>(5)), fact->GetCell(defaultWorksheetIndex, 2, 4, ObjectExt::Box<double>(2)));
// नया बिंदु जोड़ता है (3:1)
series->get_DataPoints()->AddDataPointForScatterSeries(fact->GetCell(defaultWorksheetIndex, 3, 3, ObjectExt::Box<double>(3)), fact->GetCell(defaultWorksheetIndex, 3, 4, ObjectExt::Box<double>(1)));
// नया बिंदु जोड़ता है (2:2)
series->get_DataPoints()->AddDataPointForScatterSeries(fact->GetCell(defaultWorksheetIndex, 4, 3, ObjectExt::Box<double>(2)), fact->GetCell(defaultWorksheetIndex, 4, 4, ObjectExt::Box<double>(2)));
// नया बिंदु जोड़ता है (5:1)
series->get_DataPoints()->AddDataPointForScatterSeries(fact->GetCell(defaultWorksheetIndex, 5, 3, ObjectExt::Box<double>(5)), fact->GetCell(defaultWorksheetIndex, 5, 4, ObjectExt::Box<double>(1)));
// चार्ट सीरीज़ मार्कर बदलता है
series->get_Marker()->set_Size ( 10);
series->get_Marker()->set_Symbol(MarkerStyleType::Circle);
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->set_IsColorVaried(true);
SharedPtr<IChartDataPoint> point = series->get_DataPoints()->idx_get(0);
point->get_Format()->get_Fill()->set_FillType(FillType::Solid);
point->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Cyan());
// सेक्टर बॉर्डर सेट करता है
point->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
point->get_Format()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Gray());
point->get_Format()->get_Line()->set_Width ( 3.0);
point->get_Format()->get_Line()->set_Style(LineStyle::ThinThick);
point->get_Format()->get_Line()->set_DashStyle(LineDashStyle::DashDot);
SharedPtr<IChartDataPoint> point1 = series->get_DataPoints()->idx_get(1);
point1->get_Format()->get_Fill()->set_FillType(FillType::Solid);
point1->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Brown());
// सेक्टर बॉर्डर सेट करता है
point1->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
point1->get_Format()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Blue());
point1->get_Format()->get_Line()->set_Width (3.0);
point1->get_Format()->get_Line()->set_Style(LineStyle::Single);
point1->get_Format()->get_Line()->set_DashStyle(LineDashStyle::LargeDashDot);
SharedPtr<IChartDataPoint> point2 = series->get_DataPoints()->idx_get(2);
point2->get_Format()->get_Fill()->set_FillType(FillType::Solid);
point2->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Coral());
// सेक्टर बॉर्डर सेट करता है
point2->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
point2->get_Format()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red());
point2->get_Format()->get_Line()->set_Width ( 2.0);
point2->get_Format()->get_Line()->set_Style(LineStyle::ThickThin);
point2->get_Format()->get_Line()->set_DashStyle(LineDashStyle::LargeDashDotDot);
// नई सीरीज़ की प्रत्येक श्रेणी के लिए कस्टम लेबल बनाता है
SharedPtr<IDataLabel> lbl1 = series->get_DataPoints()->idx_get(0)->get_Label();
// lbl.ShowCategoryName = true;
lbl1->get_DataLabelFormat()->set_ShowValue(true);
SharedPtr<IDataLabel> lbl2 = series->get_DataPoints()->idx_get(1)->get_Label();
lbl2->get_DataLabelFormat()->set_ShowValue(true);
lbl2->get_DataLabelFormat()->set_ShowLegendKey(true);
lbl2->get_DataLabelFormat()->set_ShowPercentage(true);
SharedPtr<IDataLabel> lbl3 = series->get_DataPoints()->idx_get(2)->get_Label();
lbl3->get_DataLabelFormat()->set_ShowSeriesName(true);
lbl3->get_DataLabelFormat()->set_ShowPercentage(true);
// चार्ट के लिए लीडर लाइन्स दिखाता है
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowLeaderLines(true);
// पाई चार्ट सेक्टर का घूर्णन कोण सेट करता है
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->set_FirstSliceAngle(180);
// प्रस्तुति सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
पाई चार्ट बनाएं
पाई चार्ट डेटा में भाग‑से‑पूरा संबंध दिखाने के लिए उपयुक्त होते हैं, विशेषकर जब डेटा में श्रेणीबद्ध लैबल के साथ संख्यात्मक मान हों। यदि आपके डेटा में बहुत सारी भाग या लैबल हों, तो आप बार चार्ट का उपयोग करने पर विचार कर सकते हैं।
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (
ChartType.Pie) जोड़ें। - चार्ट डेटा
IChartDataWorkbookतक पहुँचें। - डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- चार्ट सीरीज़ के लिए नई डेटा जोड़ें।
- पाई चार्ट के सेक्टर के लिए कस्टम रंग जोड़ें।
- सीरीज़ के लिए लेबल सेट करें।
- सीरीज़ लेबल के लिए लीडर लाइन्स सेट करें।
- पाई चार्ट स्लाइड की घूर्णन कोण सेट करें।
- संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि पाई चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ.
const String outPath = u"../out/PieChart_out.pptx";
//PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// डिफ़ॉल्ट डेटा के साथ चार्ट जोड़ता है
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Pie, 0, 0, 500, 500);
// चार्ट शीर्षक सेट करता है
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);
// डिफ़ॉल्ट जनरेटेड सीरीज़ और श्रेणियों को हटाता है
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
// चार्ट डेटा शीट का इंडेक्स सेट करता है
int defaultWorksheetIndex = 0;
// चार्ट डेटा कार्यपत्रक प्राप्त करता है
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// श्रेणियाँ जोड़ता है
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box<System::String>(u"First Qtr")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box<System::String>(u"2nd Qtr")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box<System::String>(u"3ed Qtr")));
// नई सीरीज़ जोड़ता है
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type());
// पहली चार्ट सीरीज़ लेता है
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);
// सीरीज़ डेटा भरता है
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<double>(20)));
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(50)));
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(30)));
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->set_IsColorVaried(true);
SharedPtr<IChartDataPoint> point = series->get_DataPoints()->idx_get(0);
point->get_Format()->get_Fill()->set_FillType(FillType::Solid);
point->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Cyan());
// सेक्टर बॉर्डर सेट करता है
point->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
point->get_Format()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Gray());
point->get_Format()->get_Line()->set_Width ( 3.0);
point->get_Format()->get_Line()->set_Style( LineStyle::ThinThick);
point->get_Format()->get_Line()->set_DashStyle ( LineDashStyle::DashDot);
SharedPtr<IChartDataPoint> point1 = series->get_DataPoints()->idx_get(1);
point1->get_Format()->get_Fill()->set_FillType(FillType::Solid);
point1->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Brown());
// सेक्टर बॉर्डर सेट करता है
point1->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
point1->get_Format()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Blue());
point1->get_Format()->get_Line()->set_Width (3.0);
point1->get_Format()->get_Line()->set_Style(LineStyle::Single);
point1->get_Format()->get_Line()->set_DashStyle(LineDashStyle::LargeDashDot);
SharedPtr<IChartDataPoint> point2 = series->get_DataPoints()->idx_get(2);
point2->get_Format()->get_Fill()->set_FillType(FillType::Solid);
point2->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Coral());
// सेक्टर बॉर्डर सेट करता है
point2->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
point2->get_Format()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red());
point2->get_Format()->get_Line()->set_Width (2.0);
point2->get_Format()->get_Line()->set_Style(LineStyle::ThickThin);
point2->get_Format()->get_Line()->set_DashStyle(LineDashStyle::LargeDashDotDot);
// नई सीरीज़ की प्रत्येक श्रेणी के लिए कस्टम लेबल बनाता है
SharedPtr<IDataLabel> lbl1 = series->get_DataPoints()->idx_get(0)->get_Label();
// lbl.ShowCategoryName = true;
lbl1->get_DataLabelFormat()->set_ShowValue(true);
SharedPtr<IDataLabel> lbl2 = series->get_DataPoints()->idx_get(1)->get_Label();
lbl2->get_DataLabelFormat()->set_ShowValue(true);
lbl2->get_DataLabelFormat()->set_ShowLegendKey(true);
lbl2->get_DataLabelFormat()->set_ShowPercentage(true);
SharedPtr<IDataLabel> lbl3 = series->get_DataPoints()->idx_get(2)->get_Label();
lbl3->get_DataLabelFormat()->set_ShowSeriesName(true);
lbl3->get_DataLabelFormat()->set_ShowPercentage(true);
// चार्ट के लिए लीडर लाइन्स दिखाने हेतु सीरीज़ सेट करता है
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowLeaderLines ( true);
// पाई चार्ट सेक्टर के घूर्णन कोण को सेट करता है
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->set_FirstSliceAngle ( 180);
// प्रस्तुति सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
लाइन चार्ट बनाएं
लाइन चार्ट (जिसे लाइन ग्राफ़ भी कहा जाता है) उन स्थितियों में सबसे उपयुक्त होते हैं जहाँ आप समय के साथ मूल्य परिवर्तन दिखाना चाहते हैं। लाइन चार्ट का उपयोग करके आप एक साथ कई डेटा की तुलना कर सकते हैं, समय के साथ परिवर्तन और ट्रेंड को ट्रैक कर सकते हैं, डेटा सीरीज़ में अनियमितताओं को उजागर कर सकते हैं, आदि।
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (
ChartType::Line) जोड़ें। - चार्ट डेटा
IChartDataWorkbookतक पहुँचें। - डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- चार्ट सीरीज़ के लिए नई डेटा जोड़ें।
- संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि लाइन चार्ट कैसे बनाया जाता है:
auto pres = System::MakeObject<Presentation>();
System::SharedPtr<IChart> lineChart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddChart(ChartType::Line, 10.0f, 50.0f, 600.0f, 350.0f);
pres->Save(u"lineChart.pptx", SaveFormat::Pptx);
डिफ़ॉल्ट रूप से, लाइन चार्ट पर बिंदु सीधे निरंतर रेखाओं से जुड़े होते हैं। यदि आप बिंदुओं को डैश रेखाओं से जोड़ना चाहते हैं, तो आप अपनी वांछित डैश प्रकार इस प्रकार निर्दिष्ट कर सकते हैं:
System::SharedPtr<IChart> lineChart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddChart(ChartType::Line, 10.0f, 50.0f, 600.0f, 350.0f);
for (auto&& series : lineChart->get_ChartData()->get_Series())
{
series->get_Format()->get_Line()->set_DashStyle(LineDashStyle::Dash);
}
ट्री मैप चार्ट बनाएं
ट्री मैप चार्ट बिक्री डेटा के लिए उपयुक्त होते हैं जब आप डेटा श्रेणियों के सापेक्ष आकार दिखाना चाहते हैं और साथ ही प्रत्येक श्रेणी में बड़े योगदान करने वाले आइटमों पर जल्दी से ध्यान आकर्षित करना चाहते हैं।
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (
ChartType.TreeMap) जोड़ें। - चार्ट डेटा
IChartDataWorkbookतक पहुँचें। - डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- चार्ट सीरीज़ के लिए नई डेटा जोड़ें।
- संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि ट्री मैप चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ।
const String outPath = u"../out/TreemapChart_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
System::SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Treemap, 50, 50, 500, 400);
chart->get_ChartData()->get_Categories()->Clear();
chart->get_ChartData()->get_Series()->Clear();
System::SharedPtr<IChartDataWorkbook> wb = chart->get_ChartData()->get_ChartDataWorkbook();
wb->Clear(0);
// शाखा 1
System::SharedPtr<IChartCategory> leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C1", System::ObjectExt::Box<System::String>(u"Leaf1")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem1"));
leaf->get_GroupingLevels()->SetGroupingItem(2, System::ObjectExt::Box<System::String>(u"Branch1"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C2", System::ObjectExt::Box<System::String>(u"Leaf2")));
leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C3", System::ObjectExt::Box<System::String>(u"Leaf3")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem2"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C4", System::ObjectExt::Box<System::String>(u"Leaf4")));
// शाखा 2
leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C5", System::ObjectExt::Box<System::String>(u"Leaf5")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem3"));
leaf->get_GroupingLevels()->SetGroupingItem(2, System::ObjectExt::Box<System::String>(u"Branch2"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C6", System::ObjectExt::Box<System::String>(u"Leaf6")));
leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C7", System::ObjectExt::Box<System::String>(u"Leaf7")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem4"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C8", System::ObjectExt::Box<System::String>(u"Leaf8")));
System::SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(Aspose::Slides::Charts::ChartType::Treemap);
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowCategoryName(true);
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D1", System::ObjectExt::Box<int32_t>(4)));
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D2", System::ObjectExt::Box<int32_t>(5)));
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D3", System::ObjectExt::Box<int32_t>(3)));
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D4", System::ObjectExt::Box<int32_t>(6)));
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D5", System::ObjectExt::Box<int32_t>(9)));
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D6", System::ObjectExt::Box<int32_t>(9)));
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D7", System::ObjectExt::Box<int32_t>(4)));
series->get_DataPoints()->AddDataPointForTreemapSeries(wb->GetCell(0, u"D8", System::ObjectExt::Box<int32_t>(3)));
series->set_ParentLabelLayout(Aspose::Slides::Charts::ParentLabelLayoutType::Overlapping);
// प्रस्तुति को सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
स्टॉक चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (
ChartType.OpenHighLowClose) जोड़ें। - चार्ट डेटा
IChartDataWorkbookतक पहुँचें। - डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- चार्ट सीरीज़ के लिए नई डेटा जोड़ें।
- HiLowLines फ़ॉर्मेट निर्दिष्ट करें।
- संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
स्टॉक चार्ट बनाने के लिए प्रयुक्त नमूना C++ कोड:
// दस्तावेज़ निर्देशिका का पथ.
const String outPath = u"../out/AddStockChart_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// डिफ़ॉल्ट डेटा के साथ चार्ट जोड़ता है
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::OpenHighLowClose, 0, 0, 500, 500);
// चार्ट डेटा शीट का इंडेक्स सेट करता है
int defaultWorksheetIndex = 0;
// चार्ट डेटा कार्यपत्रक प्राप्त करता है
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// डिफ़ॉल्ट जनरेटेड सीरीज़ और श्रेणियों को हटाता है
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
// श्रेणियाँ जोड़ता है
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box<System::String>(u"A")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box<System::String>(u"B")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box<System::String>(u"C")));
// नई सीरीज़ जोड़ता है
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box<System::String>(u"Open")), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 2, ObjectExt::Box<System::String>(u"High")), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 3, ObjectExt::Box<System::String>(u"Low")), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 4, ObjectExt::Box<System::String>(u"Close")), chart->get_Type());
// पहली चार्ट सीरीज़ लेता है
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);
// पहली सीरीज़ डेटा भरता है
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<double>(72)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(25)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(38)));
series = chart->get_ChartData()->get_Series()->idx_get(1);
// दूसरी सीरीज़ डेटा भरता है
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 1, 2, ObjectExt::Box<double>(172)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 2, 2, ObjectExt::Box<double>(57)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 3, 2, ObjectExt::Box<double>(57)));
series = chart->get_ChartData()->get_Series()->idx_get(2);
// दूसरी सीरीज़ डेटा भरता है
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 1, 3, ObjectExt::Box<double>(12)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 2, 3, ObjectExt::Box<double>(12)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 3, 3, ObjectExt::Box<double>(13)));
series = chart->get_ChartData()->get_Series()->idx_get(3);
// दूसरी सीरीज़ डेटा भरता है
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 1, 4, ObjectExt::Box<double>(25)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 2, 4, ObjectExt::Box<double>(38)));
series->get_DataPoints()->AddDataPointForStockSeries(fact->GetCell(defaultWorksheetIndex, 3, 4, ObjectExt::Box<double>(50)));
// सीरीज़ समूह सेट करता है
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->get_UpDownBars()->set_HasUpDownBars (true);
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->get_HiLowLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
for(int i=0;i<chart->get_ChartData()->get_Series()->get_Count();i++)
{
series = chart->get_ChartData()->get_Series()->idx_get(i);
series->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
}
// प्रस्तुति सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
बॉक्स एंड व्हिस्कर चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (
ChartType.BoxAndWhisker) जोड़ें। - चार्ट डेटा
IChartDataWorkbookतक पहुँचें। - डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- चार्ट सीरीज़ के लिए नई डेटा जोड़ें।
- संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि बॉक्स एंड व्हिस्कर चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ।
const String outPath = u"../out/BoxAndWhisker_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
System::SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::BoxAndWhisker, 50, 50, 500, 400);
chart->get_ChartData()->get_Categories()->Clear();
chart->get_ChartData()->get_Series()->Clear();
System::SharedPtr<IChartDataWorkbook> wb = chart->get_ChartData()->get_ChartDataWorkbook();
wb->Clear(0);
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A1", System::ObjectExt::Box<System::String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A2", System::ObjectExt::Box<System::String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A3", System::ObjectExt::Box<System::String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A4", System::ObjectExt::Box<System::String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A5", System::ObjectExt::Box<System::String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A6", System::ObjectExt::Box<System::String>(u"Category 1")));
System::SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(Aspose::Slides::Charts::ChartType::BoxAndWhisker);
series->set_QuartileMethod(Aspose::Slides::Charts::QuartileMethodType::Exclusive);
series->set_ShowMeanLine(true);
series->set_ShowMeanMarkers(true);
series->set_ShowInnerPoints(true);
series->set_ShowOutlierPoints(true);
series->get_DataPoints()->AddDataPointForBoxAndWhiskerSeries(wb->GetCell(0, u"B1", System::ObjectExt::Box<int32_t>(15)));
series->get_DataPoints()->AddDataPointForBoxAndWhiskerSeries(wb->GetCell(0, u"B2", System::ObjectExt::Box<int32_t>(41)));
series->get_DataPoints()->AddDataPointForBoxAndWhiskerSeries(wb->GetCell(0, u"B3", System::ObjectExt::Box<int32_t>(16)));
series->get_DataPoints()->AddDataPointForBoxAndWhiskerSeries(wb->GetCell(0, u"B4", System::ObjectExt::Box<int32_t>(10)));
series->get_DataPoints()->AddDataPointForBoxAndWhiskerSeries(wb->GetCell(0, u"B5", System::ObjectExt::Box<int32_t>(23)));
series->get_DataPoints()->AddDataPointForBoxAndWhiskerSeries(wb->GetCell(0, u"B6", System::ObjectExt::Box<int32_t>(16)));
// प्रस्तुति को सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
फ़नल चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (
ChartType.Funnel) जोड़ें। - संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि फ़नल चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ.
const String outPath = u"../out/FunnelChart_out.pptx";
//PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
System::SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Funnel, 50, 50, 500, 400);
chart->get_ChartData()->get_Categories()->Clear();
chart->get_ChartData()->get_Series()->Clear();
System::SharedPtr<IChartDataWorkbook> wb = chart->get_ChartData()->get_ChartDataWorkbook();
wb->Clear(0);
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A1", System::ObjectExt::Box<System::String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A2", System::ObjectExt::Box<System::String>(u"Category 2")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A3", System::ObjectExt::Box<System::String>(u"Category 3")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A4", System::ObjectExt::Box<System::String>(u"Category 4")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A5", System::ObjectExt::Box<System::String>(u"Category 5")));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"A6", System::ObjectExt::Box<System::String>(u"Category 6")));
System::SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(Aspose::Slides::Charts::ChartType::Funnel);
series->get_DataPoints()->AddDataPointForFunnelSeries(wb->GetCell(0, u"B1", System::ObjectExt::Box<int32_t>(50)));
series->get_DataPoints()->AddDataPointForFunnelSeries(wb->GetCell(0, u"B2", System::ObjectExt::Box<int32_t>(100)));
series->get_DataPoints()->AddDataPointForFunnelSeries(wb->GetCell(0, u"B3", System::ObjectExt::Box<int32_t>(200)));
series->get_DataPoints()->AddDataPointForFunnelSeries(wb->GetCell(0, u"B4", System::ObjectExt::Box<int32_t>(300)));
series->get_DataPoints()->AddDataPointForFunnelSeries(wb->GetCell(0, u"B5", System::ObjectExt::Box<int32_t>(400)));
series->get_DataPoints()->AddDataPointForFunnelSeries(wb->GetCell(0, u"B6", System::ObjectExt::Box<int32_t>(500)));
//प्रस्तुति को सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
सनबर्स्ट चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (
ChartType.sunburst) जोड़ें। - संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि सनबर्स्ट चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ.
const String outPath = u"../out/SunburstChart_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
System::SharedPtr<IChart> chart=slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Sunburst, 50, 50, 500, 400);
chart->get_ChartData()->get_Categories()->Clear();
chart->get_ChartData()->get_Series()->Clear();
System::SharedPtr<IChartDataWorkbook> wb = chart->get_ChartData()->get_ChartDataWorkbook();
wb->Clear(0);
// शाखा 1
System::SharedPtr<IChartCategory> leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C1", System::ObjectExt::Box<System::String>(u"Leaf1")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem1"));
leaf->get_GroupingLevels()->SetGroupingItem(2, System::ObjectExt::Box<System::String>(u"Branch1"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C2", System::ObjectExt::Box<System::String>(u"Leaf2")));
leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C3", System::ObjectExt::Box<System::String>(u"Leaf3")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem2"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C4", System::ObjectExt::Box<System::String>(u"Leaf4")));
// शाखा 2
leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C5", System::ObjectExt::Box<System::String>(u"Leaf5")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem3"));
leaf->get_GroupingLevels()->SetGroupingItem(2, System::ObjectExt::Box<System::String>(u"Branch2"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C6", System::ObjectExt::Box<System::String>(u"Leaf6")));
leaf = chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C7", System::ObjectExt::Box<System::String>(u"Leaf7")));
leaf->get_GroupingLevels()->SetGroupingItem(1, System::ObjectExt::Box<System::String>(u"Stem4"));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, u"C8", System::ObjectExt::Box<System::String>(u"Leaf8")));
System::SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(Aspose::Slides::Charts::ChartType::Sunburst);
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowCategoryName(true);
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D1", System::ObjectExt::Box<int32_t>(4)));
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D2", System::ObjectExt::Box<int32_t>(5)));
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D3", System::ObjectExt::Box<int32_t>(3)));
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D4", System::ObjectExt::Box<int32_t>(6)));
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D5", System::ObjectExt::Box<int32_t>(9)));
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D6", System::ObjectExt::Box<int32_t>(9)));
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D7", System::ObjectExt::Box<int32_t>(4)));
series->get_DataPoints()->AddDataPointForSunburstSeries(wb->GetCell(0, u"D8", System::ObjectExt::Box<int32_t>(3)));
// प्रस्तुति फ़ाइल को डिस्क पर लिखता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
हिस्टोग्राम चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डेटा के साथ चार्ट जोड़ें और वांछित प्रकार (
ChartType.Histogram) निर्दिष्ट करें। - चार्ट डेटा
IChartDataWorkbookतक पहुँचें। - डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि हिस्टोग्राम चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ।
const String outPath = u"../out/HistogramChart_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
System::SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Histogram, 50, 50, 500, 400);
chart->get_ChartData()->get_Categories()->Clear();
chart->get_ChartData()->get_Series()->Clear();
System::SharedPtr<IChartDataWorkbook> wb = chart->get_ChartData()->get_ChartDataWorkbook();
wb->Clear(0);
System::SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(Aspose::Slides::Charts::ChartType::Histogram);
series->get_DataPoints()->AddDataPointForHistogramSeries(wb->GetCell(0, u"A1", System::ObjectExt::Box<int32_t>(15)));
series->get_DataPoints()->AddDataPointForHistogramSeries(wb->GetCell(0, u"A2", System::ObjectExt::Box<int32_t>(-41)));
series->get_DataPoints()->AddDataPointForHistogramSeries(wb->GetCell(0, u"A3", System::ObjectExt::Box<int32_t>(16)));
series->get_DataPoints()->AddDataPointForHistogramSeries(wb->GetCell(0, u"A4", System::ObjectExt::Box<int32_t>(10)));
series->get_DataPoints()->AddDataPointForHistogramSeries(wb->GetCell(0, u"A5", System::ObjectExt::Box<int32_t>(-23)));
series->get_DataPoints()->AddDataPointForHistogramSeries(wb->GetCell(0, u"A6", System::ObjectExt::Box<int32_t>(16)));
chart->get_Axes()->get_HorizontalAxis()->set_AggregationType(Aspose::Slides::Charts::AxisAggregationType::Automatic);
// प्रस्तुति को सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
रडार चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डेटा के साथ चार्ट जोड़ें और वांछित प्रकार (
ChartType.Radar) निर्दिष्ट करें। - संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि रडार चार्ट कैसे बनाया जाता है:
System::SharedPtr<Presentation> presentation = System::MakeObject<Presentation>();
presentation->get_Slides()->idx_get(0)->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Radar, 20.0f, 20.0f, 400.0f, 300.0f);
presentation->Save(u"Radar-chart.pptx", Aspose::Slides::Export::SaveFormat::Pptx);
मल्टी‑कैटेगरी चार्ट बनाएं
- Presentation क्लास का एक इंस्टेन्स बनाएं।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- डिफ़ॉल्ट डेटा के साथ वांछित प्रकार (ChartType.ClusteredColumn) जोड़ें।
- चार्ट डेटा
IChartDataWorkbookतक पहुँचें। - डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करें।
- नई सीरीज़ और श्रेणियों को जोड़ें।
- चार्ट सीरीज़ के लिए नई डेटा जोड़ें।
- संशोधित प्रस्तुति को PPTX फ़ाइल में लिखें।
यह C++ कोड दिखाता है कि मल्टी‑कैटेगरी चार्ट कैसे बनाया जाता है:
// दस्तावेज़ निर्देशिका का पथ.
const String outPath = u"../out/MultiCategoryChart_out.pptx";
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// पहली स्लाइड तक पहुँचता है
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// डिफ़ॉल्ट डेटा के साथ चार्ट जोड़ता है
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::ClusteredColumn, 0, 0, 500, 500);
// चार्ट डेटा शीट के लिए इंडेक्स सेट करता है
int defaultWorksheetIndex = 0;
// चार्ट डेटा कार्यपत्रक प्राप्त करता है
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// कार्यपत्रक को साफ़ करता है
fact->Clear(defaultWorksheetIndex);
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
// श्रेणियाँ जोड़ता है
SharedPtr<IChartCategory> category = chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c2", ObjectExt::Box<System::String>(u"A")));
category->get_GroupingLevels()->SetGroupingItem(1, ObjectExt::Box<System::String>(u"Group1"));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c3", ObjectExt::Box<System::String>(u"B")));
category = chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c4", ObjectExt::Box<System::String>(u"C")));
category->get_GroupingLevels()->SetGroupingItem(1, ObjectExt::Box<System::String>(u"Group2"));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c5", ObjectExt::Box<System::String>(u"D")));
category = chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c6", ObjectExt::Box<System::String>(u"E")));
category->get_GroupingLevels()->SetGroupingItem(1, ObjectExt::Box<System::String>(u"Group3"));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c7", ObjectExt::Box<System::String>(u"F")));
category = chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c8", ObjectExt::Box<System::String>(u"G")));
category->get_GroupingLevels()->SetGroupingItem(1, ObjectExt::Box<System::String>(u"Group4"));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, u"c9", ObjectExt::Box<System::String>(u"H")));
// नई सीरीज़ जोड़ता है
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(fact->GetCell(0, u"D1", ObjectExt::Box<System::String>(u"Series 1")),
ChartType::ClusteredColumn);
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D2", ObjectExt::Box<double>(10)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D3", ObjectExt::Box<double>(20)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D4", ObjectExt::Box<double>(30)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D5", ObjectExt::Box<double>(40)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D6", ObjectExt::Box<double>(50)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D7", ObjectExt::Box<double>(60)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D8", ObjectExt::Box<double>(70)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, u"D9", ObjectExt::Box<double>(80)));
// प्रस्तुति को सहेजता है
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
मैप चार्ट बनाएं
मैप चार्ट वह विज़ुअलाइज़ेशन है जिसमें डेटा के साथ क्षेत्र दिखाया जाता है। मैप चार्ट भूगोलिक क्षेत्रों के बीच डेटा या मानों की तुलना करने के लिए सबसे उपयुक्त होते हैं।
यह C++ कोड दिखाता है कि मैप चार्ट कैसे बनाया जाता है:
auto pres = System::MakeObject<Presentation>();
auto slide = pres->get_Slides()->idx_get(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::Map, 50.0f, 50.0f, 500.0f, 400.0f);
pres->Save(u"mapChart.pptx", SaveFormat::Pptx);
कॉंबिनेशन चार्ट बनाएं
एक कॉंबिनेशन चार्ट (या कॉम्बो चार्ट) एक ही ग्राफ़ में दो या अधिक चार्ट प्रकारों को मिलाता है। यह चार्ट आपको कई डेटा सेटों के बीच अंतर को उजागर, तुलना या जांचने की सुविधा देता है, जिससे आप उनके बीच के संबंधों की पहचान कर सकते हैं।

निम्नलिखित C++ कोड उपरोक्त कॉंबिनेशन चार्ट को PowerPoint प्रस्तुति में बनाने का तरीका दर्शाता है:
static SharedPtr<IChart> CreateChartWithFirstSeries(SharedPtr<ISlide> slide)
{
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 50, 50, 600, 400);
// चार्ट शीर्षक सेट करें।
chart->set_HasTitle(true);
chart->get_ChartTitle()->AddTextFrameForOverriding(u"Chart Title");
chart->get_ChartTitle()->set_Overlay(false);
auto titleParagraph = chart->get_ChartTitle()->get_TextFrameForOverriding()->get_Paragraph(0);
auto titleFormat = titleParagraph->get_ParagraphFormat()->get_DefaultPortionFormat();
titleFormat->set_FontBold(NullableBool::False);
titleFormat->set_FontHeight(18.0);
// चार्ट लेजेंड सेट करें।
chart->get_Legend()->set_Position(LegendPositionType::Bottom);
chart->get_Legend()->get_TextFormat()->get_PortionFormat()->set_FontHeight(12.0);
// डिफ़ॉल्ट जनरेटेड सीरीज़ और श्रेणियों को हटाएँ।
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
const int worksheetIndex = 0;
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
// नई श्रेणियाँ जोड़ें।
chart->get_ChartData()->get_Categories()->Add(workbook->GetCell(worksheetIndex, 1, 0, ObjectExt::Box<String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(workbook->GetCell(worksheetIndex, 2, 0, ObjectExt::Box<String>(u"Category 2")));
chart->get_ChartData()->get_Categories()->Add(workbook->GetCell(worksheetIndex, 3, 0, ObjectExt::Box<String>(u"Category 3")));
chart->get_ChartData()->get_Categories()->Add(workbook->GetCell(worksheetIndex, 4, 0, ObjectExt::Box<String>(u"Category 4")));
// पहली सीरीज़ जोड़ें।
auto seriesNameCell = workbook->GetCell(worksheetIndex, 0, 1, ObjectExt::Box<String>(u"Series 1"));
auto series = chart->get_ChartData()->get_Series()->Add(seriesNameCell, chart->get_Type());
series->get_ParentSeriesGroup()->set_Overlap(-25);
series->get_ParentSeriesGroup()->set_GapWidth(220);
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 1, 1, ObjectExt::Box<double>(4.3)));
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 2, 1, ObjectExt::Box<double>(2.5)));
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 3, 1, ObjectExt::Box<double>(3.5)));
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 4, 1, ObjectExt::Box<double>(4.5)));
return chart;
}
static void AddSecondSeriesToChart(SharedPtr<IChart> chart)
{
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
const int worksheetIndex = 0;
auto seriesNameCell = workbook->GetCell(worksheetIndex, 0, 2, ObjectExt::Box<String>(u"Series 2"));
auto series = chart->get_ChartData()->get_Series()->Add(seriesNameCell, ChartType::ClusteredColumn);
series->get_ParentSeriesGroup()->set_Overlap(-25);
series->get_ParentSeriesGroup()->set_GapWidth(220);
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 1, 2, ObjectExt::Box<double>(2.4)));
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 2, 2, ObjectExt::Box<double>(4.4)));
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 3, 2, ObjectExt::Box<double>(1.8)));
series->get_DataPoints()->AddDataPointForBarSeries(workbook->GetCell(worksheetIndex, 4, 2, ObjectExt::Box<double>(2.8)));
}
static void AddThirdSeriesToChart(SharedPtr<IChart> chart)
{
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
const int worksheetIndex = 0;
auto seriesNameCell = workbook->GetCell(worksheetIndex, 0, 3, ObjectExt::Box<String>(u"Series 3"));
auto series = chart->get_ChartData()->get_Series()->Add(seriesNameCell, ChartType::Line);
series->get_DataPoints()->AddDataPointForLineSeries(workbook->GetCell(worksheetIndex, 1, 3, ObjectExt::Box<double>(2.0)));
series->get_DataPoints()->AddDataPointForLineSeries(workbook->GetCell(worksheetIndex, 2, 3, ObjectExt::Box<double>(2.0)));
series->get_DataPoints()->AddDataPointForLineSeries(workbook->GetCell(worksheetIndex, 3, 3, ObjectExt::Box<double>(3.0)));
series->get_DataPoints()->AddDataPointForLineSeries(workbook->GetCell(worksheetIndex, 4, 3, ObjectExt::Box<double>(5.0)));
series->set_PlotOnSecondAxis(true);
}
static void SetAxisTitle(SharedPtr<IAxis> axis, String axisTitle)
{
axis->set_HasTitle(true);
axis->get_Title()->set_Overlay(false);
auto titleParagraph = axis->get_Title()->AddTextFrameForOverriding(axisTitle)->get_Paragraph(0);
auto titleFormat = titleParagraph->get_ParagraphFormat()->get_DefaultPortionFormat();
titleFormat->set_FontBold(NullableBool::False);
titleFormat->set_FontHeight(12.0);
}
static void SetPrimaryAxesFormat(SharedPtr<IChart> chart)
{
// हॉरिज़ॉन्टल अक्ष सेट करें।
auto horizontalAxis = chart->get_Axes()->get_HorizontalAxis();
horizontalAxis->get_TextFormat()->get_PortionFormat()->set_FontHeight(12.0);
horizontalAxis->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
SetAxisTitle(horizontalAxis, u"X Axis");
// वर्टिकल अक्ष सेट करें।
auto verticalAxis = chart->get_Axes()->get_VerticalAxis();
verticalAxis->get_TextFormat()->get_PortionFormat()->set_FontHeight(12.0);
verticalAxis->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
SetAxisTitle(verticalAxis, u"Y Axis 1");
// वर्टिकल प्रमुख ग्रिडलाइन का रंग सेट करें।
auto majorGridLinesFormat = verticalAxis->get_MajorGridLinesFormat()->get_Line()->get_FillFormat();
majorGridLinesFormat->set_FillType(FillType::Solid);
majorGridLinesFormat->get_SolidFillColor()->set_Color(Color::FromArgb(217, 217, 217));
}
static void SetSecondaryAxesFormat(SharedPtr<IChart> chart)
{
// द्वितीयक हॉरिज़ॉन्टल अक्ष सेट करें।
auto secondaryHorizontalAxis = chart->get_Axes()->get_SecondaryHorizontalAxis();
secondaryHorizontalAxis->set_Position(AxisPositionType::Bottom);
secondaryHorizontalAxis->set_CrossType(CrossesType::Maximum);
secondaryHorizontalAxis->set_IsVisible(false);
secondaryHorizontalAxis->get_MajorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
secondaryHorizontalAxis->get_MinorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
// द्वितीयक वर्टिकल अक्ष सेट करें।
auto secondaryVerticalAxis = chart->get_Axes()->get_SecondaryVerticalAxis();
secondaryVerticalAxis->set_Position(AxisPositionType::Right);
secondaryVerticalAxis->get_TextFormat()->get_PortionFormat()->set_FontHeight(12.0);
secondaryVerticalAxis->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
secondaryVerticalAxis->get_MajorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
secondaryVerticalAxis->get_MinorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
SetAxisTitle(secondaryVerticalAxis, u"Y Axis 2");
}
static void CreateComboChart()
{
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = CreateChartWithFirstSeries(slide);
AddSecondSeriesToChart(chart);
AddThirdSeriesToChart(chart);
SetPrimaryAxesFormat(chart);
SetSecondaryAxesFormat(chart);
presentation->Save(u"combo-chart.pptx", SaveFormat::Pptx);
presentation->Dispose();
}
चार्ट अपडेट करें
- उस प्रस्तुति को दर्शाने वाला एक Presentation क्लास का इंस्टेन्स बनाएं जिसमें चार्ट मौजूद है।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- सभी शैप्स को पार करके वांछित चार्ट खोजें।
- चार्ट डेटा कार्यपत्रक तक पहुँचें।
- सीरीज़ मूल्यों को बदलकर चार्ट डेटा सीरीज़ को संशोधित करें।
- नई सीरीज़ जोड़ें और उसमें डेटा भरें।
- संशोधित प्रस्तुति को PPTX फ़ाइल के रूप में लिखें।
यह C++ कोड दिखाता है कि चार्ट को कैसे अपडेट किया जाता है:
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"ExistingChart.pptx");
// पहली स्लाइडमार्कर तक पहुँचता है
System::SharedPtr<ISlide> sld = pres->get_Slides()->idx_get(0);
// डिफ़ॉल्ट डेटा के साथ चार्ट जोड़ता है
System::SharedPtr<IChart> chart = System::ExplicitCast<Aspose::Slides::Charts::IChart>(sld->get_Shapes()->idx_get(0));
// चार्ट डेटा शीट के लिए इंडेक्स सेट करता है
int32_t defaultWorksheetIndex = 0;
// चार्ट डेटा कार्यपत्रक प्राप्त करता है
System::SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// चार्ट श्रेणी का नाम बदलता है
fact->GetCell(defaultWorksheetIndex, 1, 0, System::ObjectExt::Box<System::String>(u"Modified Category 1"));
fact->GetCell(defaultWorksheetIndex, 2, 0, System::ObjectExt::Box<System::String>(u"Modified Category 2"));
// पहली चार्ट सीरीज़ लेता है
System::SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);
// सीरीज़ डेटा अपडेट करता है
fact->GetCell(defaultWorksheetIndex, 0, 1, System::ObjectExt::Box<System::String>(u"New_Series1"));
// सीरीज़ नाम संशोधित करता है
series->get_DataPoints()->idx_get(0)->get_Value()->set_Data(System::ObjectExt::Box<int32_t>(90));
series->get_DataPoints()->idx_get(1)->get_Value()->set_Data(System::ObjectExt::Box<int32_t>(123));
series->get_DataPoints()->idx_get(2)->get_Value()->set_Data(System::ObjectExt::Box<int32_t>(44));
// दूसरी चार्ट सीरीज़ लेता है
series = chart->get_ChartData()->get_Series()->idx_get(1);
// अब सीरीज़ डेटा अपडेट कर रहा है
fact->GetCell(defaultWorksheetIndex, 0, 2, System::ObjectExt::Box<System::String>(u"New_Series2"));
// सीरीज़ नाम संशोधित करता है
series->get_DataPoints()->idx_get(0)->get_Value()->set_Data(System::ObjectExt::Box<int32_t>(23));
series->get_DataPoints()->idx_get(1)->get_Value()->set_Data(System::ObjectExt::Box<int32_t>(67));
series->get_DataPoints()->idx_get(2)->get_Value()->set_Data(System::ObjectExt::Box<int32_t>(99));
// अब, नई सीरीज़ जोड़ रहा है
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 3, System::ObjectExt::Box<System::String>(u"Series 3")), chart->get_Type());
// 3rd चार्ट सीरीज़ लेता है
series = chart->get_ChartData()->get_Series()->idx_get(2);
// अब सीरीज़ डेटा भर रहा है
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 1, 3, System::ObjectExt::Box<int32_t>(20)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 2, 3, System::ObjectExt::Box<int32_t>(50)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 3, 3, System::ObjectExt::Box<int32_t>(30)));
chart->set_Type(Aspose::Slides::Charts::ChartType::ClusteredCylinder);
// चार्ट के साथ प्रस्तुति सहेजें
pres->Save(u"AsposeChartModified_out.pptx", Aspose::Slides::Export::SaveFormat::Pptx);
चार्ट के डेटा रेंज को सेट करें
- उस Presentation क्लास की एक इंस्टेन्स खोलें जिसमें चार्ट मौजूद है।
- स्लाइड का संदर्भ उसके इंडेक्स से प्राप्त करें।
- सभी शैप्स को पार करके वांछित चार्ट खोजें।
- चार्ट डेटा तक पहुँचें और रेंज सेट करें।
- संशोधित प्रस्तुति को PPTX फ़ाइल के रूप में सहेजें।
यह C++ कोड दिखाता है कि चार्ट के डेटा रेंज को कैसे सेट किया जाता है:
// दस्तावेज़ निर्देशिका का पथ.
String dataDir = GetDataPath();
// PPTX फ़ाइल का प्रतिनिधित्व करने वाली Presentation क्लास का इंस्टैंस बनाता है
auto presentation = System::MakeObject<Presentation>(dataDir + u"ExistingChart.pptx");
// पहली स्लाइडमार्कर तक पहुँचता है और डिफ़ॉल्ट डेटा के साथ चार्ट जोड़ता है
auto slide = presentation->get_Slides()->idx_get(0);
auto chart = System::ExplicitCast<IChart>(slide->get_Shapes()->idx_get(0));
chart->get_ChartData()->SetRange(u"Sheet1!A1:B4");
presentation->Save(dataDir + u"SetDataRange_out.pptx", SaveFormat::Pptx);
चार्ट में डिफ़ॉल्ट मार्कर का उपयोग करें
जब आप चार्ट में डिफ़ॉल्ट मार्कर का उपयोग करते हैं, तो प्रत्येक चार्ट सीरीज़ को स्वचालित रूप से अलग‑अलग डिफ़ॉल्ट मार्कर प्रतीक मिलते हैं।
यह C++ कोड दर्शाता है कि चार्ट सीरीज़ मार्कर को स्वचालित रूप से कैसे सेट करें:
// दस्तावेज़ निर्देशिका का पथ.
String dataDir = GetDataPath();
auto pres = System::MakeObject<Presentation>();
auto slide = pres->get_Slides()->idx_get(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::LineWithMarkers, 10.0f, 10.0f, 400.0f, 400.0f);
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
auto wb = chart->get_ChartData()->get_ChartDataWorkbook();
chart->get_ChartData()->get_Series()->Add(wb->GetCell(0, 0, 1, ObjectExt::Box<String>(u"Series 1")), chart->get_Type());
auto series = chart->get_ChartData()->get_Series()->idx_get(0);
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, 1, 0, ObjectExt::Box<String>(u"C1")));
series->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 1, 1, ObjectExt::Box<int32_t>(24)));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, 2, 0, ObjectExt::Box<String>(u"C2")));
series->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 2, 1, ObjectExt::Box<int32_t>(23)));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, 3, 0, ObjectExt::Box<String>(u"C3")));
series->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 3, 1, ObjectExt::Box<int32_t>(-10)));
chart->get_ChartData()->get_Categories()->Add(wb->GetCell(0, 4, 0, ObjectExt::Box<String>(u"C4")));
series->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 4, 1, nullptr));
chart->get_ChartData()->get_Series()->Add(wb->GetCell(0, 0, 2, ObjectExt::Box<String>(u"Series 2")), chart->get_Type());
// दूसरी चार्ट सीरीज़ लेता है
auto series2 = chart->get_ChartData()->get_Series()->idx_get(1);
// सीरीज़ डेटा भरता है
series2->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 1, 2, ObjectExt::Box<int32_t>(30)));
series2->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 2, 2, ObjectExt::Box<int32_t>(10)));
series2->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 3, 2, ObjectExt::Box<int32_t>(60)));
series2->get_DataPoints()->AddDataPointForLineSeries(wb->GetCell(0, 4, 2, ObjectExt::Box<int32_t>(40)));
chart->set_HasLegend(true);
chart->get_Legend()->set_Overlay(false);
pres->Save(dataDir + u"DefaultMarkersInChart.pptx", SaveFormat::Pptx);
अक्सर पूछे जाने वाले प्रश्न
Aspose.Slides किन चार्ट प्रकारों का समर्थन करता है?
Aspose.Slides कई प्रकार के चार्ट सपोर्ट करता है, जिनमें बार, लाइन, पाई, एरिया, स्कैटर, हिस्टोग्राम, रडार और कई अन्य शामिल हैं। यह लचीलापन आपको अपने डेटा विज़ुअलाइज़ेशन की आवश्यकताओं के लिए सबसे उपयुक्त चार्ट प्रकार चुनने की अनुमति देता है।
मैं स्लाइड में नया चार्ट कैसे जोड़ूं?
एक चार्ट जोड़ने के लिए, सबसे पहले आप Presentation क्लास की एक इंस्टेन्स बनाते हैं, फिर उसके इंडेक्स से वांछित स्लाइड प्राप्त करते हैं, और अंत में चार्ट जोड़ने की मेथड को कॉल करके चार्ट प्रकार और प्रारंभिक डेटा निर्दिष्ट करते हैं। यह प्रक्रिया चार्ट को सीधे आपकी प्रस्तुति में एकीकृत कर देती है।
मैं चार्ट में प्रदर्शित डेटा कैसे अपडेट करूँ?
आप चार्ट का डेटा अपडेट कर सकते हैं जब आप उसके डेटा वर्कबुक (IChartDataWorkbook) तक पहुँचते हैं, किसी भी डिफ़ॉल्ट सीरीज़ और श्रेणियों को साफ़ करते हैं, और फिर अपनी कस्टम डेटा जोड़ते हैं। इससे आप प्रोग्रामेटिक रूप से चार्ट को नवीनतम डेटा के साथ रिफ़्रेश कर सकते हैं।
क्या चार्ट की उपस्थिति को अनुकूलित करना संभव है?
हाँ, Aspose.Slides व्यापक अनुकूलन विकल्प प्रदान करता है। आप रंग, फ़ॉन्ट, लेबल, लेजेंड और अन्य फ़ॉर्मेटिंग तत्वों को संशोधित करके चार्ट की उपस्थिति को अपनी विशिष्ट डिज़ाइन आवश्यकताओं के अनुसार ढाल सकते हैं।