C++ का उपयोग करके प्रस्तुतियों में चार्ट डेटा लेबल्स का प्रबंधन
परिचय
डेटा लेबल्स चार्ट सीरीज़ और व्यक्तिगत डेटा पॉइंट्स की जानकारी दिखाते हैं, जिससे पाठकों को मानों की पहचान करने और चार्ट को समझने में सहायता मिलती है। यह लेख बताता है कि मानों को कैसे स्वरूपित किया जाए, प्रतिशत कैसे प्रदर्शित किए जाएँ, लेबल टेक्स्ट को कैसे पढ़ा जाए, एक्सिस अधिकतम से परे लेबल्स को कैसे नियंत्रित किया जाए, श्रेणी एक्सिस लेबल स्पेसिंग को कैसे समायोजित किया जाए, और पाई चार्ट लेबल्स की स्थिति कैसे निर्धारित की जाए।
दृश्यमान डेटा लेबल्स की गिनती
प्रस्तुति प्रकाशित करने से पहले यह जांचने के लिए कि कितने डेटा लेबल्स प्रदर्शित करने के लिए सक्षम हैं, get_CountOfVisibleDataLabels का उपयोग करें। get_Count के विपरीत, जो संग्रह में कुल लेबल्स की संख्या वापस करता है, यह श्रृंखला के डिफ़ॉल्ट और व्यक्तिगत लेबल सेटिंग्स को ध्यान में रखता है।
यह उदाहरण एक कॉलम चार्ट बनाता है जिसमें एक सीरीज़ और तीन डेटा पॉइंट्स हैं। यह सीरीज़ के get_Labels संग्रह को एक्सेस करता है और सेटिंग्स बदलते समय दृश्यमान गिनती को प्रिंट करता है: 0, 3, 2, 3। कुल गिनती 3 ही रहती है।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IDataLabel.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <system/console.h>
#include <system/object_ext.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace System;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 50, 50, 500, 300);
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
auto seriesCell = workbook->GetCell(0, 0, 1, ObjectExt::Box<String>(u"Values"));
auto series = chart->get_ChartData()->get_Series()->Add(seriesCell, chart->get_Type());
for (auto i = 0; i < 3; i++)
{
auto categoryCell = workbook->GetCell(0, i + 1, 0, ObjectExt::Box(String::Format(u"Category {0}", i + 1)));
chart->get_ChartData()->get_Categories()->Add(categoryCell);
auto valueCell = workbook->GetCell(0, i + 1, 1, ObjectExt::Box((i + 1) * 10));
series->get_DataPoints()->AddDataPointForBarSeries(valueCell);
}
auto labels = series->get_Labels();
Console::WriteLine(String::Format(u"Total: {0}; visible: {1}", labels->get_Count(), labels->get_CountOfVisibleDataLabels())); // कुल: 3; दृश्यमान: 0
labels->get_DefaultDataLabelFormat()->set_ShowValue(true);
Console::WriteLine(String::Format(u"Visible: {0}", labels->get_CountOfVisibleDataLabels())); // दृश्यमान: 3
labels->idx_get(1)->get_DataLabelFormat()->set_ShowValue(false);
Console::WriteLine(String::Format(u"Visible: {0}", labels->get_CountOfVisibleDataLabels())); // दृश्यमान: 2
labels->idx_get(1)->get_DataLabelFormat()->set_ShowLegendKey(true);
Console::WriteLine(String::Format(u"Visible: {0}", labels->get_CountOfVisibleDataLabels())); // दृश्यमान: 3
सीरीज़ का get_DefaultDataLabelFormat डिफ़ॉल्ट सेटिंग्स प्रदान करता है। उस पर true के साथ set_ShowValue कॉल करने से सभी तीन लेबल्स के लिए मान दिखाए जाते हैं। एक लेबल के get_DataLabelFormat के माध्यम से false पास करने से उस चयनित लेबल के लिए वह सेटिंग ओवरराइड हो जाती है। true के साथ set_ShowLegendKey कॉल करने से वह लेबल फिर से दृश्यमान गिना जाता है, जबकि उसका मान छुपा रहता है।
दृश्यमान गिनती दृश्यता सेटिंग्स को दर्शाती है। यह नहीं मापती कि लेबल्स ओवरलैप होते हैं, क्लिप होते हैं, या रेंडर किए गए चार्ट में पढ़ने योग्य हैं या नहीं।
चार्ट डेटा लेबल्स में डेटा प्रिसीजन सेट करें
सीरीज़ मानों को स्वरूपित करने के लिए set_NumberFormatOfValues का उपयोग करें। यह उदाहरण एक लाइन चार्ट बनाता है जिसमें डिफ़ॉल्ट डेटा है, उसका डेटा टेबल दिखाता है, और पहली सीरीज़ के लिए मान लेबल सक्षम करता है। फ़ॉर्मेट #,##0.00 हज़ारों विभाजक और दो दशमलव स्थान दिखाता है बिना आधारभूत मानों को बदले।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::Line, 50, 50, 450, 300);
chart->set_HasDataTable(true);
auto series = chart->get_ChartData()->get_Series()->idx_get(0);
series->set_NumberFormatOfValues(u"#,##0.00");
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowValue(true);
presentation->Save(u"PrecisionOfDatalabels_out.pptx", SaveFormat::Pptx);
चार्ट की एम्बेडेड वर्कबुक में संख्यात्मक सेल्स को स्वरूपित करने के लिए देखें Set Custom Number Formats for Workbook Cells। वह उदाहरण भी दिखाता है कि स्रोत सेल फ़ॉर्मेट्स को बनाए रखते हुए मान लेबल्स उनके स्रोत सेल फ़ॉर्मेट्स का अनुसरण करते हैं।
लेबल्स के रूप में प्रतिशत प्रदर्शित करें
स्टैक्ड कॉलम चार्ट में, प्रत्येक मान को उसकी श्रेणी कुल का प्रतिशत गणना करें और उसे get_TextFrameForOverriding द्वारा लौटाए गए टेक्स्ट फ्रेम में असाइन करें। यह उदाहरण डिफ़ॉल्ट चार्ट डेटा का उपयोग करता है और 8‑पॉइंट फ़ॉन्ट में दो दशमलव स्थान के साथ प्रतिशत प्रदर्शित करता है। शून्य कुल वाली श्रेणियों को विभाजन शून्य से बचने के लिए छोड़ा जाता है। यदि चार्ट डेटा बदलता है तो कस्टम लेबल टेक्स्ट को पुनः गणना करें।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IChartDataPoint.h>
#include <DOM/Chart/IDoubleChartValue.h>
#include <DOM/Chart/IDataLabel.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <DOM/Portion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/ITextFrame.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IPortionCollection.h>
#include <system/convert.h>
#include <vector>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::StackedColumn, 20, 20, 400, 400);
auto categoryTotals = std::vector<double>(chart->get_ChartData()->get_Categories()->get_Count(), 0.0);
for (auto k = 0; k < chart->get_ChartData()->get_Categories()->get_Count(); k++)
{
for (auto i = 0; i < chart->get_ChartData()->get_Series()->get_Count(); i++)
{
auto series = chart->get_ChartData()->get_Series()->idx_get(i);
auto pointValue = Convert::ToDouble(series->get_DataPoint(k)->get_Value()->get_Data());
categoryTotals[k] += pointValue;
}
}
for (auto x = 0; x < chart->get_ChartData()->get_Series()->get_Count(); x++)
{
auto series = chart->get_ChartData()->get_Series()->idx_get(x);
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowLegendKey(false);
for (auto j = 0; j < series->get_DataPoints()->get_Count(); j++)
{
auto label = series->get_DataPoint(j)->get_Label();
if (categoryTotals[j] == 0)
{
continue;
}
auto pointValue = Convert::ToDouble(series->get_DataPoint(j)->get_Value()->get_Data());
auto dataPointPercent = (pointValue / categoryTotals[j]) * 100;
auto portion = MakeObject<Portion>();
portion->set_Text(String::Format(u"{0:F2} %", dataPointPercent));
portion->get_PortionFormat()->set_FontHeight(8.0f);
label->get_TextFrameForOverriding()->set_Text(u"");
auto paragraph = label->get_TextFrameForOverriding()->get_Paragraphs()->idx_get(0);
paragraph->get_Portions()->Add(portion);
label->get_DataLabelFormat()->set_ShowValue(true);
label->get_DataLabelFormat()->set_ShowSeriesName(false);
label->get_DataLabelFormat()->set_ShowPercentage(false);
label->get_DataLabelFormat()->set_ShowLegendKey(false);
label->get_DataLabelFormat()->set_ShowCategoryName(false);
label->get_DataLabelFormat()->set_ShowBubbleSize(false);
}
}
presentation->Save(u"DisplayPercentageAsLabels_out.pptx", SaveFormat::Pptx);
चार्ट डेटा लेबल्स के साथ प्रतिशत चिह्न सेट करें
जब मान अंश के रूप में संग्रहीत होते हैं, तो प्रतिशत प्रदर्शित करने के लिए set_NumberFormat का उपयोग करें। स्रोत सेल्स से स्वतंत्र रूप से लेबल फ़ॉर्मेट लागू करने के लिए set_IsNumberFormatLinkedToSource को false पास करें।
यह उदाहरण चार श्रेणियों में लाल और नीली सीरीज़ के साथ 100% स्टैक्ड कॉलम चार्ट बनाता है। प्रत्येक मान जोड़ी का योग 1 है। लेबल फ़ॉर्मेट 0.0% 0.30 को 30.0% के रूप में दिखाता है, जबकि वर्टिकल एक्सिस दो दशमलव स्थान का उपयोग करता है। दोनों सीरीज़ सफेद, 10‑पॉइंट लेबल टेक्स्ट का उपयोग करती हैं।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IAxesManager.h>
#include <DOM/Chart/IAxis.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IFormat.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <DOM/Chart/IChartTextFormat.h>
#include <DOM/Chart/IChartPortionFormat.h>
#include <DOM/FillType.h>
#include <DOM/IFillFormat.h>
#include <DOM/IColorFormat.h>
#include <drawing/color.h>
#include <system/object_ext.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::PercentsStackedColumn, 20, 20, 500, 400);
chart->get_Axes()->get_VerticalAxis()->set_IsNumberFormatLinkedToSource(false);
chart->get_Axes()->get_VerticalAxis()->set_NumberFormat(u"0.00%");
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
auto worksheetIndex = 0;
for (auto i = 0; i < 4; i++)
{
auto categoryCell = workbook->GetCell(worksheetIndex, i + 1, 0, ObjectExt::Box(String::Format(u"Category {0}", i + 1)));
chart->get_ChartData()->get_Categories()->Add(categoryCell);
}
String seriesNames[] = { u"Reds", u"Blues" };
Color seriesColors[] = { Color::get_Red(), Color::get_Blue() };
double values[2][4] = { { 0.30, 0.50, 0.80, 0.65 }, { 0.70, 0.50, 0.20, 0.35 } };
for (auto i = 0; i < 2; i++)
{
auto seriesCell = workbook->GetCell(worksheetIndex, 0, i + 1, ObjectExt::Box(seriesNames[i]));
auto series = chart->get_ChartData()->get_Series()->Add(seriesCell, chart->get_Type());
for (auto j = 0; j < 4; j++)
{
auto valueCell = workbook->GetCell(worksheetIndex, j + 1, i + 1, ObjectExt::Box(values[i][j]));
series->get_DataPoints()->AddDataPointForBarSeries(valueCell);
}
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(seriesColors[i]);
auto labelFormat = series->get_Labels()->get_DefaultDataLabelFormat();
labelFormat->set_ShowValue(true);
labelFormat->set_IsNumberFormatLinkedToSource(false);
labelFormat->set_NumberFormat(u"0.0%");
labelFormat->get_TextFormat()->get_PortionFormat()->set_FontHeight(10);
labelFormat->get_TextFormat()->get_PortionFormat()->get_FillFormat()->set_FillType(FillType::Solid);
labelFormat->get_TextFormat()->get_PortionFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_White());
}
presentation->Save(u"SetDataLabelsPercentageSign_out.pptx", SaveFormat::Pptx);
डेटा लेबल्स का वास्तविक पाठ पढ़ें
डेटा लेबल की सेटिंग्स द्वारा उत्पन्न पाठ प्राप्त करने के लिए GetActualLabelText का उपयोग करें। यह रिपोर्ट के लिए लेबल्स निकालते समय, प्रस्तुति सामग्री खोजते समय, या उत्पन्न चार्ट्स को सत्यापित करते समय उपयोगी है। नीचे दिए गए उदाहरण में, डिफ़ॉल्ट data label format प्रत्येक श्रेणी नाम, सीरीज़ नाम और मान को संयोजित करता है। एक पॉइंट अपना मान प्रतिशत के रूप में स्वरूपित करता है, और दूसरा get_TextFrameForOverriding से कस्टम टेक्स्ट उपयोग करता है।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IChartDataPoint.h>
#include <DOM/Chart/IDoubleChartValue.h>
#include <DOM/Chart/IDataLabel.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <DOM/ITextFrame.h>
#include <system/console.h>
#include <system/object_ext.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace System;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20, 20, 500, 300);
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
auto firstCategoryCell = workbook->GetCell(0, 1, 0, ObjectExt::Box<String>(u"Q1"));
chart->get_ChartData()->get_Categories()->Add(firstCategoryCell);
auto secondCategoryCell = workbook->GetCell(0, 2, 0, ObjectExt::Box<String>(u"Q2"));
chart->get_ChartData()->get_Categories()->Add(secondCategoryCell);
auto northSeriesCell = workbook->GetCell(0, 0, 1, ObjectExt::Box<String>(u"North"));
auto north = chart->get_ChartData()->get_Series()->Add(northSeriesCell, chart->get_Type());
auto northFirstValueCell = workbook->GetCell(0, 1, 1, ObjectExt::Box(0.25));
north->get_DataPoints()->AddDataPointForBarSeries(northFirstValueCell);
auto northSecondValueCell = workbook->GetCell(0, 2, 1, ObjectExt::Box(0.75));
north->get_DataPoints()->AddDataPointForBarSeries(northSecondValueCell);
auto southSeriesCell = workbook->GetCell(0, 0, 2, ObjectExt::Box<String>(u"South"));
auto south = chart->get_ChartData()->get_Series()->Add(southSeriesCell, chart->get_Type());
auto southFirstValueCell = workbook->GetCell(0, 1, 2, ObjectExt::Box(0.40));
south->get_DataPoints()->AddDataPointForBarSeries(southFirstValueCell);
auto southSecondValueCell = workbook->GetCell(0, 2, 2, ObjectExt::Box(0.60));
south->get_DataPoints()->AddDataPointForBarSeries(southSecondValueCell);
for (auto i = 0; i < chart->get_ChartData()->get_Series()->get_Count(); i++)
{
auto series = chart->get_ChartData()->get_Series()->idx_get(i);
auto format = series->get_Labels()->get_DefaultDataLabelFormat();
format->set_ShowCategoryName(true);
format->set_ShowSeriesName(true);
format->set_ShowValue(true);
}
north->get_Label(1)->get_DataLabelFormat()->set_IsNumberFormatLinkedToSource(false);
north->get_Label(1)->get_DataLabelFormat()->set_NumberFormat(u"0%");
south->get_Label(0)->get_TextFrameForOverriding()->set_Text(u"Reviewed");
for (auto i = 0; i < chart->get_ChartData()->get_Series()->get_Count(); i++)
{
auto series = chart->get_ChartData()->get_Series()->idx_get(i);
for (auto j = 0; j < series->get_DataPoints()->get_Count(); j++)
{
auto point = series->get_DataPoint(j);
auto label = point->get_Label();
if (!label->get_IsVisible())
{
continue;
}
Console::WriteLine(String::Format(u"Value: {0}; label: {1}", point->get_Value()->get_Data(), label->GetActualLabelText()));
}
}
डेटा पॉइंट में संग्रहीत संख्या 0.75 ही रहती है, भले ही उसका लेबल 75% के साथ श्रेणी और सीरीज़ नाम दिखाए। कस्टम टेक्स्ट उत्पन्न लेबल टेक्स्ट को बदल देता है। GetActualLabelText दोनों मामलों में परिणामी लेबल स्ट्रिंग लौटाता है। दृश्यमान लेबल्स केवल निकालने के लिए ऊपर दिखाए अनुसार get_IsVisible को अलग से जांचें।
एक्सिस अधिकतम से परे डेटा लेबल्स को नियंत्रित करें
जब आप मैन्युअल रूप से एक्सिस रेंज सीमित करते हैं, तो कुछ डेटा पॉइंट्स उसके अधिकतम से अधिक हो सकते हैं। क्या उनके डेटा लेबल दिखाए जाएँ, यह नियंत्रित करने के लिए set_ShowDataLabelsOverMaximum का उपयोग करें। यह सेटिंग लेबल दृश्यता बदलती है; यह एक्सिस रेंज या आधारभूत डेटा मानों को नहीं बदलती।
नीचे दिया गया उदाहरण 60 और 120 मानों के साथ 2D क्लस्टर्ड कॉलम चार्ट बनाता है। यह वर्टिकल एक्सिस पर set_IsAutomaticMaxValue को false और set_MaxValue को 100 सेट करता है। पहली स्लाइड अधिकतम से परे लेबल्स की अनुमति देती है; उसकी एक कॉपी में उन्हें निष्क्रिय किया गया है। दोनों स्लाइड्स DataLabelsOverMaximum.pptx में सहेजी गई हैं।
set_ShowValue के साथ मान लेबल्स सक्षम करें। चार्ट‑लेवल सेटिंग स्वयं मान प्रदर्शित नहीं करती और व्यक्तिगत लेबल की डिसेबल्ड वैल्यू डिस्प्ले को ओवरराइड नहीं करती। यह उदाहरण पूरे सीरीज़ के लिए मान सक्षम करता है और set_Position का उपयोग करके प्रत्येक कॉलम के बाहर के अंत में लेबल्स रखता है।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IAxesManager.h>
#include <DOM/Chart/IAxis.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <DOM/Chart/LegendDataLabelPosition.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 50, 50, 600, 400);
chart->set_HasLegend(false);
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
auto firstCategory = workbook->GetCell(0, 1, 0, ObjectExt::Box<String>(u"Within range"));
auto secondCategory = workbook->GetCell(0, 2, 0, ObjectExt::Box<String>(u"Above maximum"));
chart->get_ChartData()->get_Categories()->Add(firstCategory);
chart->get_ChartData()->get_Categories()->Add(secondCategory);
auto seriesName = workbook->GetCell(0, 0, 1, ObjectExt::Box<String>(u"Values"));
auto series = chart->get_ChartData()->get_Series()->Add(seriesName, chart->get_Type());
auto firstValue = workbook->GetCell(0, 1, 1, ObjectExt::Box(60));
auto secondValue = workbook->GetCell(0, 2, 1, ObjectExt::Box(120));
series->get_DataPoints()->AddDataPointForBarSeries(firstValue);
series->get_DataPoints()->AddDataPointForBarSeries(secondValue);
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowValue(true);
series->get_Labels()->get_DefaultDataLabelFormat()->set_Position(LegendDataLabelPosition::OutsideEnd);
chart->get_Axes()->get_VerticalAxis()->set_IsAutomaticMaxValue(false);
chart->get_Axes()->get_VerticalAxis()->set_MaxValue(100);
chart->set_ShowDataLabelsOverMaximum(true);
auto secondSlide = presentation->get_Slides()->AddClone(slide);
auto secondChart = ExplicitCast<IChart>(secondSlide->get_Shape(0));
secondChart->set_ShowDataLabelsOverMaximum(false);
presentation->Save(u"DataLabelsOverMaximum.pptx", SaveFormat::Pptx);
निम्न छवियाँ Microsoft PowerPoint द्वारा रेंडर किए गए सहेजे हुए स्लाइड्स दिखाती हैं। true के साथ लेबल 120 ऊपर की सीमा पर दृश्यमान होता है; false के साथ यह छुपा होता है। लेबल 60 दृश्यमान रह जाता है, एक्सिस अधिकतम 100 पर बना रहता है, और दूसरा डेटा पॉइंट दोनों स्थितियों में 120 रहता है।
| ShowDataLabelsOverMaximum = true | ShowDataLabelsOverMaximum = false |
|---|---|
![]() |
![]() |
Chart Type
यह उदाहरण वैल्यू एक्सिस वाले 2D कॉलम चार्ट का उपयोग करता है। पाई और डोनट चार्ट जैसे वैल्यू एक्सिस के बिना चार्ट्स के पास इस प्रकार सीमित करने के लिए कोई एक्सिस अधिकतम नहीं होता।एक्सिस से लेबल दूरी सेट करें
श्रेणी एक्सिस लेबल और एक्सिस के बीच की दूरी को नियंत्रित करने के लिए set_LabelOffset का उपयोग करें। मान एक्सिस लेबल्स के अधिकतम फ़ॉन्ट आकार का प्रतिशत होता है। यह उदाहरण एक क्लस्टर्ड कॉलम चार्ट बनाता है और क्षैतिज एक्सिस लेबल ऑफसेट को 500 सेट करता है। यह सेटिंग श्रेणी एक्सिस लेबल्स को प्रभावित करती है, न कि व्यक्तिगत डेटा पॉइंट्स से संलग्न लेबल्स को।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IAxesManager.h>
#include <DOM/Chart/IAxis.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20, 20, 500, 300);
chart->get_Axes()->get_HorizontalAxis()->set_LabelOffset(500);
presentation->Save(u"SetCategoryAxisLabelDistance_out.pptx", SaveFormat::Pptx);
लेबल स्थान समायोजित करें
पाई चार्ट में, डेटा लेबल स्थितियों को समायोजित करके स्पेसिंग सुधारें और लीडर लाइन्स के लिए जगह बनाएं।
यह उदाहरण पहले डेटा पॉइंट का मान दिखाता है, उसका लेबल स्लाइस के बाहर रखता है, और उसके ऑफसेट को समायोजित करने के लिए set_X और set_Y का उपयोग करता है। ये ऑफसेट क्रमशः चार्ट की चौड़ाई और ऊँचाई के सापेक्ष होते हैं।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IDataLabel.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <DOM/Chart/LegendDataLabelPosition.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::Pie, 50, 50, 200, 200);
auto series = chart->get_ChartData()->get_Series();
auto label = series->idx_get(0)->get_Label(0);
label->get_DataLabelFormat()->set_ShowValue(true);
label->get_DataLabelFormat()->set_Position(LegendDataLabelPosition::OutsideEnd);
label->set_X(0.71f);
label->set_Y(0.04f);
presentation->Save(u"presentation.pptx", SaveFormat::Pptx);

लीडर लाइन्स स्वरूपित करें
जब पाई चार्ट लेबल्स अपने स्लाइस के बाहर होते हैं, तो लीडर लाइन्स पाठकों को प्रत्येक मान को सही स्लाइस से मिलाने में मदद करती हैं। एक कंट्रास्टिंग रंग और थोड़ा मोटी लाइन इन कनेक्शनों को आसानी से पढ़ने योग्य बना सकती है, जबकि पारदर्शिता और डैश्ड शैली लाइन्स को दृश्य रूप से कम बाधित रखती है।
सीरीज़ के डेटा लेबल संग्रह स्तर पर लीडर लाइन्स को स्वरूपित करने के लिए get_LeaderLinesFormat का उपयोग करें। series->get_Labels()->get_LeaderLinesFormat()->get_Line() में सेटिंग्स संग्रह पर लागू होती हैं, न कि व्यक्तिगत लेबल पर।
यह उदाहरण डिफ़ॉल्ट डेटा के साथ एक पाई चार्ट बनाता है, स्लाइस के बाहर मान दिखाता है, और set_ShowLeaderLines के साथ लीडर लाइन्स सक्षम करता है। यह दो लेबल्स को उनके स्लाइस से दूर ले जाने के लिए set_X और set_Y ऑफसेट का उपयोग करता है, जो चार्ट की चौड़ाई और ऊँचाई के अंश के रूप में व्यक्त होते हैं। कोई इनपुट प्रस्तुति आवश्यक नहीं है।
get_FillFormat द्वारा लौटाए गए फ़िल फ़ॉर्मेट का उपयोग करके अल्फा मान 255 में से 191 वाला ठोस नीला रंग सेट किया जाता है, जो लगभग 25 % पारदर्शिता देता है। set_Width मोटाई को 2 पॉइंट सेट करता है, और set_DashStyle लाइन को डैश्ड बनाता है।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IDataLabel.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <DOM/Chart/IChartLinesFormat.h>
#include <DOM/Chart/LegendDataLabelPosition.h>
#include <DOM/ILineFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/IColorFormat.h>
#include <DOM/FillType.h>
#include <DOM/LineDashStyle.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::Pie, 80, 50, 560, 400);
chart->set_HasLegend(false);
auto series = chart->get_ChartData()->get_Series()->idx_get(0);
auto labelFormat = series->get_Labels()->get_DefaultDataLabelFormat();
labelFormat->set_ShowValue(true);
labelFormat->set_Position(LegendDataLabelPosition::OutsideEnd);
labelFormat->set_ShowLeaderLines(true);
// दो लेबल्स को उनके स्लाइस से दूर ले जाएँ।
series->get_Label(0)->set_X(0.10f);
series->get_Label(0)->set_Y(-0.05f);
series->get_Label(1)->set_X(-0.10f);
series->get_Label(1)->set_Y(0.05f);
auto line = series->get_Labels()->get_LeaderLinesFormat()->get_Line();
line->get_FillFormat()->set_FillType(FillType::Solid);
line->get_FillFormat()->get_SolidFillColor()->set_Color(Color::FromArgb(191, 30, 90, 160));
line->set_Width(2);
line->set_DashStyle(LineDashStyle::Dash);
presentation->Save(u"FormattedLeaderLines.pptx", SaveFormat::Pptx);
लीडर लाइन्स को सक्षम करने से यह गारंटी नहीं मिलती कि प्रत्येक लेबल के लिए लाइन दिखाई देगी। दृश्यता लेबल प्लेसमेंट और चार्ट के लेआउट व्यवहार पर निर्भर करती है। इस उदाहरण में, दो स्थानांतरित लेबल्स के पास दृश्यमान लीडर लाइन्स हैं; स्लाइस के पास रहने वाले लेबल्स को उनकी आवश्यकता नहीं होती।
नीचे छवि FormattedLeaderLines.pptx को Aspose.Slides के साथ रेंडर दिखाती है:

कॉलम चार्ट के ऊपर कई पंक्तियों के डेटा लेबल्स जोड़ें
यह उदाहरण दो पंक्तियों के डेटा लेबल्स के साथ एक कॉलम चार्ट बनाता है जो प्लॉट एरिया के ऊपर होते हैं। सीरीज़ A दृश्यमान कॉलम्स दिखाता है, जबकि सीरीज़ B और सीरीज़ C अतिरिक्त लेबल्स प्रदान करते हैं। उनकी कॉलम्स को फ़िल और आउटलाइन हटाकर छुपा दिया गया है। सभी तीन सीरीज़ को समान श्रेणी केंद्रों पर संरेखित करने के लिए set_Overlap का उपयोग किया जाता है।
get_PlotArea सेटिंग्स लेबल पंक्तियों के लिए स्थान आरक्षित करती हैं। ValidateChartLayout डिफ़ॉल्ट स्थितियों की गणना करने के बाद, set_X और set_Y क्षैतिज संरेखण बनाए रखते हैं और लेबल्स को दो पंक्तियों में व्यवस्थित करने के लिए लंबवत ऑफसेट लागू करते हैं। संख्याएँ सीरीज़ मानों से जुड़ी डेटा लेबल्स बनी रहती हैं; केवल पंक्ति शीर्षक अलग टेक्स्ट शैप्स होते हैं।
#include <DOM/Presentation.h>
#include <DOM/ISlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/IChart.h>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IChartDataPoint.h>
#include <DOM/Chart/IChartSeriesGroup.h>
#include <DOM/Chart/IFormat.h>
#include <DOM/Chart/IDataLabelCollection.h>
#include <DOM/Chart/IDataLabelFormat.h>
#include <DOM/Chart/IDataLabel.h>
#include <DOM/Chart/IChartTextFormat.h>
#include <DOM/Chart/IChartPortionFormat.h>
#include <DOM/Chart/LegendDataLabelPosition.h>
#include <DOM/Chart/IAxesManager.h>
#include <DOM/Chart/IAxis.h>
#include <DOM/Chart/IChartPlotArea.h>
#include <DOM/Chart/LayoutTargetType.h>
#include <DOM/FillType.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IColorFormat.h>
#include <DOM/ShapeType.h>
#include <DOM/IAutoShape.h>
#include <DOM/ITextFrame.h>
#include <DOM/ITextFrameFormat.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortionCollection.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/object_ext.h>
#include <system/smart_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 40, 40, 640, 200);
chart->set_HasTitle(false);
chart->set_HasLegend(false);
chart->get_TextFormat()->get_PortionFormat()->set_FontHeight(12);
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
workbook->Clear(0);
String categories[] = { u"North", u"South", u"East", u"West" };
String seriesNames[] = { u"Series A", u"Series B", u"Series C" };
double seriesValues[3][4] = {
{ 35, 42, 28, 47 },
{ 22, 31, 19, 26 },
{ 12, 16, 14, 18 }
};
for (auto categoryIndex = 0; categoryIndex < 4; categoryIndex++)
{
auto categoryCell = workbook->GetCell(0, categoryIndex + 1, 0, ObjectExt::Box(categories[categoryIndex]));
chart->get_ChartData()->get_Categories()->Add(categoryCell);
}
for (auto seriesIndex = 0; seriesIndex < 3; seriesIndex++)
{
auto seriesCell = workbook->GetCell(0, 0, seriesIndex + 1, ObjectExt::Box(seriesNames[seriesIndex]));
auto series = chart->get_ChartData()->get_Series()->Add(seriesCell, ChartType::ClusteredColumn);
for (auto categoryIndex = 0; categoryIndex < 4; categoryIndex++)
{
auto valueCell = workbook->GetCell(0, categoryIndex + 1, seriesIndex + 1, ObjectExt::Box(seriesValues[seriesIndex][categoryIndex]));
series->get_DataPoints()->AddDataPointForBarSeries(valueCell);
}
if (seriesIndex > 0)
{
// B और C के कॉलम छुपाएँ, लेकिन उनके डेटा लेबल रखें।
series->get_Format()->get_Fill()->set_FillType(FillType::NoFill);
series->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::NoFill);
auto labelFormat = series->get_Labels()->get_DefaultDataLabelFormat();
labelFormat->set_ShowValue(true);
labelFormat->get_TextFormat()->get_PortionFormat()->set_FontHeight(12);
auto labelFill = labelFormat->get_TextFormat()->get_PortionFormat()->get_FillFormat();
labelFill->set_FillType(FillType::Solid);
labelFill->get_SolidFillColor()->set_Color(Color::get_Black());
labelFormat->set_Position(LegendDataLabelPosition::InsideBase);
}
}
// तीनों सीरीज़ को समान श्रेणी केंद्रों के साथ संरेखित करें।
chart->get_ChartData()->get_Series()->idx_get(0)->get_ParentSeriesGroup()->set_Overlap(100);
// इस संक्षिप्त उदाहरण के लिए कम ग्रिडलाइन का उपयोग करें।
chart->get_Axes()->get_VerticalAxis()->set_IsAutomaticMajorUnit(false);
chart->get_Axes()->get_VerticalAxis()->set_MajorUnit(10);
// डेटा लेबल की दो पंक्तियों के लिए प्लॉट के ऊपर स्थान आरक्षित करें।
chart->get_PlotArea()->set_LayoutTargetType(LayoutTargetType::Inner);
chart->get_PlotArea()->set_X(0.15f);
chart->get_PlotArea()->set_Y(0.32f);
chart->get_PlotArea()->set_Width(0.80f);
chart->get_PlotArea()->set_Height(0.48f);
chart->ValidateChartLayout();
for (auto seriesIndex = 1; seriesIndex < 3; seriesIndex++)
{
auto series = chart->get_ChartData()->get_Series()->idx_get(seriesIndex);
auto rowTop = seriesIndex == 1 ? 0.15f : 0.03f;
for (auto categoryIndex = 0; categoryIndex < 4; categoryIndex++)
{
auto dataLabel = series->get_DataPoint(categoryIndex)->get_Label();
// डिफ़ॉल्ट क्षैतिज स्थिति रखें। Y डिफ़ॉल्ट लेबल स्थिति से एक ऑफसेट है
// डिफ़ॉल्ट लेबल स्थिति से, जो चार्ट-ऊँचाई के अंश के रूप में व्यक्त है।
dataLabel->set_X(0);
dataLabel->set_Y(rowTop - dataLabel->get_ActualY() / chart->get_Height());
}
// केवल पंक्ति शीर्षक एक अलग टेक्स्ट आकार है।
auto rowHeading = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, chart->get_X(), chart->get_Y() + rowTop * chart->get_Height(), 85, 18);
rowHeading->get_FillFormat()->set_FillType(FillType::NoFill);
rowHeading->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
rowHeading->AddTextFrame(seriesNames[seriesIndex]);
rowHeading->get_TextFrame()->get_TextFrameFormat()->set_MarginTop(0);
rowHeading->get_TextFrame()->get_TextFrameFormat()->set_MarginBottom(0);
auto headingFormat = rowHeading->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(0)->get_PortionFormat();
headingFormat->set_FontHeight(12);
headingFormat->get_FillFormat()->set_FillType(FillType::Solid);
headingFormat->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());
}
presentation->Save(u"multiple-rows-of-labels.pptx", SaveFormat::Pptx);

FAQ
भारी चार्ट्स में डेटा लेबल्स के ओवरलैप को कैसे रोकें?
स्वचालित लेबल प्लेसमेंट, लीडर लाइन्स और छोटा फ़ॉन्ट आकार मिलाकर उपयोग करें; यदि आवश्यक हो तो कुछ फ़ील्ड्स (जैसे श्रेणी) को छुपाएँ या केवल अत्यधिक मानों या मुख्य बिंदुओं के लिए लेबल्स दिखाएँ।
शून्य, नकारात्मक या खाली मानों के लिए लेबल्स को केवल कैसे निष्क्रिय करें?
लेबल्स सक्षम करने से पहले डेटा पॉइंट्स को फ़िल्टर करें और 0, नकारात्मक मानों या अनुपलब्ध मानों के लिए डिस्प्ले बंद करें, जैसा कि परिभाषित नियम में बताया गया है।
PDF/इमेज निर्यात करते समय एकसमान लेबल स्टाइल कैसे सुनिश्चित करें?
फ़ॉन्ट फैंटी और आकार को स्पष्ट रूप से सेट करें और रेंडरिंग वातावरण में फ़ॉन्ट उपलब्ध है, यह सुनिश्चित करें ताकि फ़ॉलबैक न हो।

