Python में PowerPoint प्रस्तुति चार्ट बनाना या अपडेट करना
सारांश
यह लेख Aspose.Slides for Python via Java का उपयोग करके चार्ट बनाने और अनुकूलित करने के बारे में एक व्यापक गाइड प्रदान करता है। आप सीखेंगे कि कैसे प्रोग्रामेटिक रूप से स्लाइड में एक चार्ट जोड़ा जाए, उसे डेटा से भरें, और विभिन्न फ़ॉर्मेटिंग विकल्प लागू करके अपने विशिष्ट डिज़ाइन आवश्यकताओं को पूरा किया जाए। लेख में विस्तृत कोड उदाहरण प्रत्येक चरण को दर्शाते हैं, प्रस्तुति और चार्ट ऑब्जेक्ट को इनिशियलाइज़ करने से लेकर सीरीज़, अक्ष और लेजेंड को कॉन्फ़िगर करने तक। इस गाइड का अनुसरण करके, आप अपने Python अनुप्रयोगों में डायनेमिक चार्ट जेनरेशन को एकीकृत करने की ठोस समझ प्राप्त करेंगे, जिससे डेटा‑ड्रिवन प्रस्तुतियों को बनाना सरल हो जाता है।
चार्ट बनाएं
चार्ट लोगों को डेटा को तेज़ी से दृश्यात्मक बनाने और ऐसे अंतर्दृष्टि प्रदान करने में मदद करते हैं जो तालिका या स्प्रेडशीट से तुरंत स्पष्ट नहीं होते।
चार्ट क्यों बनाएं?
- प्रस्तुति में एक ही स्लाइड पर बड़ी मात्रा में डेटा को एकत्रित, संक्षिप्त या सारांशित करना;
- डेटा में पैटर्न और रुझान उजागर करना;
- समय के साथ या एक विशिष्ट माप इकाई के अनुसार डेटा की दिशा और गति का अनुमान लगाना;
- आउट्लायर्स, विचलन, त्रुटियाँ और असंगत डेटा की पहचान करना;
- जटिल डेटा को संप्रेषित या प्रस्तुत करना।
PowerPoint में आप Insert फ़ंक्शन के माध्यम से चार्ट बना सकते हैं, जो कई प्रकार के चार्ट डिज़ाइन करने के लिए टेम्पलेट प्रदान करता है। Aspose.Slides का उपयोग करके आप सामान्य चार्ट (लोकप्रिय चार्ट प्रकारों पर आधारित) और कस्टम चार्ट दोनों बना सकते हैं।
Note
Use the ChartType enumeration in the asposeslides.api package. The values in this enumeration correspond to different chart types.क्लस्टर्ड कॉलम चार्ट बनाएं
This example uses addChart to create a clustered column chart that compares two series across three categories. The series use red and green fills, and individual labels demonstrate category names, series names, and values. Worksheet index 0 refers to the first sheet in the embedded chart workbook.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, FillType, NullableBool, Presentation, SaveFormat
Color = jpype.JClass("java.awt.Color")
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 300)
chart.getChartTitle().addTextFrameForOverriding("Sample Title")
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True_)
chart.getChartTitle().setHeight(20)
chart.setTitle(True)
workbook = chart.getChartData().getChartDataWorkbook()
worksheet_index = 0
chart.getChartData().getSeries().clear()
chart.getChartData().getCategories().clear()
series_name_cell = workbook.getCell(worksheet_index, 0, 1, "Series 1")
chart.getChartData().getSeries().add(series_name_cell, chart.getType())
series_name_cell = workbook.getCell(worksheet_index, 0, 2, "Series 2")
chart.getChartData().getSeries().add(series_name_cell, chart.getType())
category_cell = workbook.getCell(worksheet_index, 1, 0, "Category 1")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(worksheet_index, 2, 0, "Category 2")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(worksheet_index, 3, 0, "Category 3")
chart.getChartData().getCategories().add(category_cell)
series = chart.getChartData().getSeries().get_Item(0)
value_cell = workbook.getCell(worksheet_index, 1, 1, 20)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 2, 1, 50)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 3, 1, 30)
series.getDataPoints().addDataPointForBarSeries(value_cell)
series.getFormat().getFill().setFillType(FillType.Solid)
series.getFormat().getFill().getSolidFillColor().setColor(Color.RED)
series = chart.getChartData().getSeries().get_Item(1)
value_cell = workbook.getCell(worksheet_index, 1, 2, 30)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 2, 2, 10)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 3, 2, 60)
series.getDataPoints().addDataPointForBarSeries(value_cell)
series.getFormat().getFill().setFillType(FillType.Solid)
color = Color(0, 128, 0)
series.getFormat().getFill().getSolidFillColor().setColor(color)
label = series.getDataPoints().get_Item(0).getLabel()
label.getDataLabelFormat().setShowCategoryName(True)
label = series.getDataPoints().get_Item(1).getLabel()
label.getDataLabelFormat().setShowSeriesName(True)
label = series.getDataPoints().get_Item(2).getLabel()
label.getDataLabelFormat().setShowValue(True)
label.getDataLabelFormat().setShowSeriesName(True)
label.getDataLabelFormat().setSeparator("/")
presentation.save("AsposeChart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

स्कैटर चार्ट बनाएं
Scatter charts (also known as scatter plots or x-y graphs) are often used to check for patterns or demonstrate correlations between two variables.
Use a scatter chart when:
- You have paired numerical data.
- You have two variables that pair well together.
- You want to determine whether the two variables are related.
- You have an independent variable that has multiple values for a dependent variable.
यह उदाहरण दो सेट के x‑y मूल्यों को प्लॉट करता है। पहली श्रृंखला सीधी लाइनों के साथ स्टार मार्कर का उपयोग करती है, जबकि दूसरी स्मूद लाइनों के साथ सर्कल मार्कर; दोनों का मार्कर आकार 10 है, जिसे setSize द्वारा कॉन्फ़िगर किया गया है। setSymbol मेथड मार्कर की आकृति को नियंत्रित करता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, MarkerStyleType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.ScatterWithSmoothLines, 20, 20, 500, 300)
workbook = chart.getChartData().getChartDataWorkbook()
worksheet_index = 0
chart.getChartData().getSeries().clear()
series_name_cell = workbook.getCell(worksheet_index, 1, 1, "Series 1")
chart.getChartData().getSeries().add(series_name_cell, chart.getType())
series_name_cell = workbook.getCell(worksheet_index, 1, 3, "Series 2")
chart.getChartData().getSeries().add(series_name_cell, chart.getType())
series = chart.getChartData().getSeries().get_Item(0)
x_value_cell = workbook.getCell(worksheet_index, 2, 1, 1)
y_value_cell = workbook.getCell(worksheet_index, 2, 2, 3)
series.getDataPoints().addDataPointForScatterSeries(x_value_cell, y_value_cell)
x_value_cell = workbook.getCell(worksheet_index, 3, 1, 2)
y_value_cell = workbook.getCell(worksheet_index, 3, 2, 10)
series.getDataPoints().addDataPointForScatterSeries(x_value_cell, y_value_cell)
series.setType(ChartType.ScatterWithStraightLinesAndMarkers)
series.getMarker().setSize(10)
series.getMarker().setSymbol(MarkerStyleType.Star)
series = chart.getChartData().getSeries().get_Item(1)
x_value_cell = workbook.getCell(worksheet_index, 2, 3, 5)
y_value_cell = workbook.getCell(worksheet_index, 2, 4, 2)
series.getDataPoints().addDataPointForScatterSeries(x_value_cell, y_value_cell)
x_value_cell = workbook.getCell(worksheet_index, 3, 3, 3)
y_value_cell = workbook.getCell(worksheet_index, 3, 4, 1)
series.getDataPoints().addDataPointForScatterSeries(x_value_cell, y_value_cell)
x_value_cell = workbook.getCell(worksheet_index, 4, 3, 2)
y_value_cell = workbook.getCell(worksheet_index, 4, 4, 2)
series.getDataPoints().addDataPointForScatterSeries(x_value_cell, y_value_cell)
x_value_cell = workbook.getCell(worksheet_index, 5, 3, 5)
y_value_cell = workbook.getCell(worksheet_index, 5, 4, 1)
series.getDataPoints().addDataPointForScatterSeries(x_value_cell, y_value_cell)
series.getMarker().setSize(10)
series.getMarker().setSymbol(MarkerStyleType.Circle)
presentation.save("AsposeChart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

पाई चार्ट बनाएं
Pie charts are best used to show the part‑to‑whole relationship in data, especially when the data contains categorical labels with numeric values. However, if your data contains many parts or labels, you might want to consider using a bar chart instead.
यह उदाहरण तीन तिमाही मूल्यों के साथ एक पाई चार्ट बनाता है। प्रत्येक स्लाइस में कस्टम फ़िल और बॉर्डर है, और लेबल विभिन्न संयोजनों में मूल्य, प्रतिशत और श्रृंखला जानकारी दिखाते हैं। setFirstSliceAngle मेथड पहले स्लाइस को 180 डिग्री पर शुरू होने के लिए सेट करता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, FillType, LineDashStyle, LineStyle, NullableBool, Presentation, SaveFormat
Color = jpype.JClass("java.awt.Color")
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.Pie, 20, 20, 500, 300)
chart.getChartTitle().addTextFrameForOverriding("Sample Title")
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True_)
chart.getChartTitle().setHeight(20)
chart.setTitle(True)
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(True)
workbook = chart.getChartData().getChartDataWorkbook()
worksheet_index = 0
chart.getChartData().getSeries().clear()
chart.getChartData().getCategories().clear()
category_cell = workbook.getCell(0, 1, 0, "1st Qtr")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, 2, 0, "2nd Qtr")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, 3, 0, "3rd Qtr")
chart.getChartData().getCategories().add(category_cell)
series_name_cell = workbook.getCell(0, 0, 1, "Series 1")
series = chart.getChartData().getSeries().add(series_name_cell, chart.getType())
value_cell = workbook.getCell(worksheet_index, 1, 1, 20)
series.getDataPoints().addDataPointForPieSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 2, 1, 50)
series.getDataPoints().addDataPointForPieSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 3, 1, 30)
series.getDataPoints().addDataPointForPieSeries(value_cell)
chart.getChartData().getSeriesGroups().get_Item(0).setColorVaried(True)
first_slice = series.getDataPoints().get_Item(0)
first_slice.getFormat().getFill().setFillType(FillType.Solid)
first_slice.getFormat().getFill().getSolidFillColor().setColor(Color.CYAN)
first_slice.getFormat().getLine().getFillFormat().setFillType(FillType.Solid)
first_slice.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GRAY)
first_slice.getFormat().getLine().setWidth(3.0)
first_slice.getFormat().getLine().setStyle(LineStyle.ThinThick)
first_slice.getFormat().getLine().setDashStyle(LineDashStyle.LargeDash)
second_slice = series.getDataPoints().get_Item(1)
second_slice.getFormat().getFill().setFillType(FillType.Solid)
color = Color(165, 42, 42)
second_slice.getFormat().getFill().getSolidFillColor().setColor(color)
second_slice.getFormat().getLine().getFillFormat().setFillType(FillType.Solid)
second_slice.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE)
second_slice.getFormat().getLine().setWidth(3.0)
second_slice.getFormat().getLine().setStyle(LineStyle.Single)
second_slice.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDot)
third_slice = series.getDataPoints().get_Item(2)
third_slice.getFormat().getFill().setFillType(FillType.Solid)
color = Color(255, 127, 80)
third_slice.getFormat().getFill().getSolidFillColor().setColor(color)
third_slice.getFormat().getLine().getFillFormat().setFillType(FillType.Solid)
third_slice.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED)
third_slice.getFormat().getLine().setWidth(2.0)
third_slice.getFormat().getLine().setStyle(LineStyle.ThinThin)
third_slice.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDotDot)
first_label = series.getDataPoints().get_Item(0).getLabel()
first_label.getDataLabelFormat().setShowValue(True)
second_label = series.getDataPoints().get_Item(1).getLabel()
second_label.getDataLabelFormat().setShowValue(True)
second_label.getDataLabelFormat().setShowLegendKey(True)
second_label.getDataLabelFormat().setShowPercentage(True)
third_label = series.getDataPoints().get_Item(2).getLabel()
third_label.getDataLabelFormat().setShowSeriesName(True)
third_label.getDataLabelFormat().setShowPercentage(True)
series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(True)
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180)
presentation.save("PieChart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

लाइन चार्ट बनाएं
Line charts (also known as line graphs) are best used in situations where you want to demonstrate changes in value over time. Using a line chart, you can compare a large amount of data at once, track changes and trends over time, highlight anomalies in data series, and more.
This example uses addChart to create a line chart with the default series and categories, then saves the presentation as PPTX.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
line_chart = slide.getShapes().addChart(ChartType.Line, 20, 20, 500, 300)
presentation.save("line_chart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
डिफ़ॉल्ट रूप से, लाइन चार्ट में बिंदु सीधे निरंतर लाइनों से जुड़े होते हैं। यदि आप बिंदुओं को डैश द्वारा जोड़ना चाहते हैं, तो setDashStyle को LineDashStyle से मान के साथ कॉल करें:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, LineDashStyle, Presentation
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
line_chart = slide.getShapes().addChart(ChartType.Line, 20, 20, 500, 300)
for series in line_chart.getChartData().getSeries():
series.getFormat().getLine().setDashStyle(LineDashStyle.Dash)
finally:
presentation.dispose()
परिणाम:

ट्री मैप चार्ट बनाएं
Tree map charts are best used for sales data when you want to show the relative size of data categories and quickly draw attention to items that are large contributors within each category.
यह उदाहरण चार टर्म्स और दो शाखाओं में समूहित आठ लीव्स के साथ एक ट्री मैप बनाता है। setGroupingItem मेथड स्तर 1 पर स्टेम और स्तर 2 पर ब्रांच असाइन करता है। मान सापेक्ष आयत आकार निर्धारित करते हैं, जबकि श्रेणी लेबल और ओवरलैपिंग पैरेंट लेबल पदानुक्रम को दर्शाते हैं।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, ParentLabelLayoutType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.Treemap, 20, 20, 500, 300)
chart.getChartData().getCategories().clear()
chart.getChartData().getSeries().clear()
workbook = chart.getChartData().getChartDataWorkbook()
workbook.clear(0)
# शाखा 1
category_cell = workbook.getCell(0, "C1", "Leaf1")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem1")
leaf.getGroupingLevels().setGroupingItem(2, "Branch1")
category_cell = workbook.getCell(0, "C2", "Leaf2")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "C3", "Leaf3")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem2")
category_cell = workbook.getCell(0, "C4", "Leaf4")
chart.getChartData().getCategories().add(category_cell)
# शाखा 2
category_cell = workbook.getCell(0, "C5", "Leaf5")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem3")
leaf.getGroupingLevels().setGroupingItem(2, "Branch2")
category_cell = workbook.getCell(0, "C6", "Leaf6")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "C7", "Leaf7")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem4")
category_cell = workbook.getCell(0, "C8", "Leaf8")
chart.getChartData().getCategories().add(category_cell)
series = chart.getChartData().getSeries().add(ChartType.Treemap)
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(True)
value_cell = workbook.getCell(0, "D1", 4)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
value_cell = workbook.getCell(0, "D2", 5)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
value_cell = workbook.getCell(0, "D3", 3)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
value_cell = workbook.getCell(0, "D4", 6)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
value_cell = workbook.getCell(0, "D5", 9)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
value_cell = workbook.getCell(0, "D6", 9)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
value_cell = workbook.getCell(0, "D7", 4)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
value_cell = workbook.getCell(0, "D8", 3)
series.getDataPoints().addDataPointForTreemapSeries(value_cell)
series.setParentLabelLayout(ParentLabelLayoutType.Overlapping)
presentation.save("Treemap.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

वॉटरफ़ॉल चार्ट बनाएं
A waterfall chart shows how positive and negative changes contribute to a final value. For example, a profit breakdown can start with revenue, subtract costs, and add other income. Change columns float between the previous and new running values, while total columns extend from zero to the accumulated value.
The following example uses amounts in thousands of US dollars:
| श्रेणी | वर्कबुक मान | कॉलम प्रकार |
|---|---|---|
| राजस्व | 1000 | वृद्धि |
| बिक्री लागत | -400 | कमी |
| सकल लाभ | 600 | मध्यवर्ती कुल |
| संचालन खर्च | -200 | कमी |
| अन्य आय | 50 | वृद्धि |
| शुद्ध लाभ | 450 | अंतिम कुल |
एक बिंदु को मध्यवर्ती या अंतिम कुल के रूप में चिन्हित करने के लिए, उसके setSetAsTotal मेथड को True के साथ कॉल करें। वास्तविक संचित राशि उस बिंदु की वर्कबुक सेल में दें: 600 सकल लाभ (1000 - 400) के लिए और 450 शुद्ध लाभ (600 - 200 + 50) के लिए। यह मेथड कॉलम को कुल के रूप में चिन्हित करता है; यह सेल मूल्य की गणना या भराव नहीं करता। शून्य को प्लेसहोल्डर के रूप में उपयोग न करें या कुल बिंदु के लिए कोई अन्य परिवर्तन न जोड़ें। एक कुल कॉलम संचित मान को दिखाता है बिना उसे फिर से चलती मान में जोड़ें।
यह पूर्ण Python उदाहरण ChartType के Waterfall सदस्य का उपयोग करके एक चार्ट बनाता है, डिफ़ॉल्ट डेटा हटाता है और एम्बेडेड वर्कबुक को भरता है। वर्कशीट इंडेक्स 0 पहली वर्कशीट को चुनता है; कॉलम A में श्रेणी नाम और कॉलम B में मान होते हैं। प्रत्येक मान सेल को addDataPointForWaterfallSeries से जोड़ा जाता है। शून्य‑आधारित बिंदु इंडेक्स 2 और 5 क्रमशः मध्यवर्ती और अंतिम कुल को दर्शाते हैं। setShowValue को True से कॉल करने पर कॉलम पर राशि दिखती है। इनपुट प्रस्तुति या वर्कबुक की आवश्यकता नहीं है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.Waterfall, 20, 20, 680, 200)
chart.setTitle(True)
chart.getChartTitle().addTextFrameForOverriding("Profit breakdown (USD thousands)")
chart.getChartTitle().setOverlay(False)
chart.setLegend(False)
chart.getChartData().getSeries().clear()
chart.getChartData().getCategories().clear()
workbook = chart.getChartData().getChartDataWorkbook()
worksheet_index = 0
workbook.clear(worksheet_index)
series_name_cell = workbook.getCell(worksheet_index, 0, 1, "Profit")
series = chart.getChartData().getSeries().add(series_name_cell, ChartType.Waterfall)
categories = ["Revenue", "Cost of sales", "Gross profit", "Operating expenses", "Other income", "Net profit"]
values = [1000, -400, 600, -200, 50, 450]
for i in range(len(categories)):
category_cell = workbook.getCell(worksheet_index, i + 1, 0, categories[i])
chart.getChartData().getCategories().add(category_cell)
value_cell = workbook.getCell(worksheet_index, i + 1, 1, values[i])
series.getDataPoints().addDataPointForWaterfallSeries(value_cell)
# तीसरे और छठे बिंदु कुल दर्शाते हैं, अतिरिक्त परिवर्तन नहीं।
series.getDataPoints().get_Item(2).setSetAsTotal(True)
series.getDataPoints().get_Item(5).setSetAsTotal(True)
series.setShowConnectorLines(True)
series.getLabels().getDefaultDataLabelFormat().setShowValue(True)
presentation.save("WaterfallChart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
क्रमिक कॉलम को जोड़ने वाली रेखाएँ दिखाने के लिए श्रृंखला‑स्तर के setShowConnectorLines मेथड को True के साथ कॉल करें। इन रेखाओं को छिपाने के लिए, उदाहरण में मेथड कॉल को series.setShowConnectorLines(False) से बदलें और फिर सहेजें। इससे केवल रेखा की दृश्यता बदलती है, डेटा या कुल नहीं।
सहेजी गई प्रस्तुति में 600 का सकल लाभ और 450 का शुद्ध लाभ दिखाया गया है, दोनों कुल शून्य से शुरू होते हैं:

स्टॉक चार्ट बनाएं
Stock charts are used to display financial data such as open, high, low, and close prices, helping analyze market trends and volatility. They offer essential insights into stock performance, aiding investors and analysts in making informed decisions.
यह उदाहरण चार श्रृंखलाओं के साथ एक ओपन‑हाई‑लो‑क्लोज़ चार्ट बनाता है और तीन श्रेणियों को शामिल करता है। setUpDownBars मेथड अप/डाउन बार को सक्षम करता है, और getHiLowLinesFormat हाई‑लो लाइनों को नियंत्रित करता है जो मूल्य सीमा दर्शाते हैं, जबकि व्यक्तिगत श्रृंखला रेखाएँ और मामूली क्षैतिज ग्रिडलाइन छुपी रहती हैं।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, FillType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.OpenHighLowClose, 20, 20, 500, 300, False)
workbook = chart.getChartData().getChartDataWorkbook()
category_cell = workbook.getCell(0, 1, 0, "A")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, 2, 0, "B")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, 3, 0, "C")
chart.getChartData().getCategories().add(category_cell)
series_name_cell = workbook.getCell(0, 0, 1, "Open")
chart.getChartData().getSeries().add(series_name_cell, ChartType.OpenHighLowClose)
series_name_cell = workbook.getCell(0, 0, 2, "High")
chart.getChartData().getSeries().add(series_name_cell, ChartType.OpenHighLowClose)
series_name_cell = workbook.getCell(0, 0, 3, "Low")
chart.getChartData().getSeries().add(series_name_cell, ChartType.OpenHighLowClose)
series_name_cell = workbook.getCell(0, 0, 4, "Close")
chart.getChartData().getSeries().add(series_name_cell, ChartType.OpenHighLowClose)
series = chart.getChartData().getSeries().get_Item(0)
value_cell = workbook.getCell(0, 1, 1, 72)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 2, 1, 25)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 3, 1, 38)
series.getDataPoints().addDataPointForStockSeries(value_cell)
series = chart.getChartData().getSeries().get_Item(1)
value_cell = workbook.getCell(0, 1, 2, 172)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 2, 2, 57)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 3, 2, 57)
series.getDataPoints().addDataPointForStockSeries(value_cell)
series = chart.getChartData().getSeries().get_Item(2)
value_cell = workbook.getCell(0, 1, 3, 12)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 2, 3, 12)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 3, 3, 13)
series.getDataPoints().addDataPointForStockSeries(value_cell)
series = chart.getChartData().getSeries().get_Item(3)
value_cell = workbook.getCell(0, 1, 4, 25)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 2, 4, 38)
series.getDataPoints().addDataPointForStockSeries(value_cell)
value_cell = workbook.getCell(0, 3, 4, 50)
series.getDataPoints().addDataPointForStockSeries(value_cell)
chart.getChartData().getSeriesGroups().get_Item(0).getUpDownBars().setUpDownBars(True)
chart.getChartData().getSeriesGroups().get_Item(0).getHiLowLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid)
for stock_series in chart.getChartData().getSeries():
stock_series.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
presentation.save("Stock-chart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

बॉक्स और व्हिस्कर चार्ट बनाएं
Box and whisker charts are used to display the distribution of data by summarizing key statistical measures, such as the median, quartiles, and potential outliers. They are particularly useful in exploratory data analysis and statistical studies to quickly understand data variability and identify any anomalies.
यह उदाहरण छह मानों से एक बॉक्स और व्हिस्कर चार्ट बनाता है। setQuartileMethod मेथड विशिष्ट क्वार्टाइल गणना चुनता है। उदाहरण में मीन्स लाइनों, मीन्स मार्करों, आंतरिक बिंदुओं और आउट्लायर बिंदुओं को भी सक्षम किया गया है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, QuartileMethodType, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.BoxAndWhisker, 20, 20, 500, 300)
chart.getChartData().getCategories().clear()
chart.getChartData().getSeries().clear()
workbook = chart.getChartData().getChartDataWorkbook()
workbook.clear(0)
category_cell = workbook.getCell(0, "A1", "Category 1")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A2", "Category 2")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A3", "Category 3")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A4", "Category 4")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A5", "Category 5")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A6", "Category 6")
chart.getChartData().getCategories().add(category_cell)
series = chart.getChartData().getSeries().add(ChartType.BoxAndWhisker)
series.setQuartileMethod(QuartileMethodType.Exclusive)
series.setShowMeanLine(True)
series.setShowMeanMarkers(True)
series.setShowInnerPoints(True)
series.setShowOutlierPoints(True)
value_cell = workbook.getCell(0, "B1", 15)
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(value_cell)
value_cell = workbook.getCell(0, "B2", 41)
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(value_cell)
value_cell = workbook.getCell(0, "B3", 16)
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(value_cell)
value_cell = workbook.getCell(0, "B4", 10)
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(value_cell)
value_cell = workbook.getCell(0, "B5", 23)
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(value_cell)
value_cell = workbook.getCell(0, "B6", 16)
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(value_cell)
presentation.save("BoxAndWhisker.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
फ़नल चार्ट बनाएं
Funnel charts are used to visualize processes that involve sequential stages, where the volume of data decreases as it progresses from one step to the next. They are especially helpful for analyzing conversion rates, identifying bottlenecks, and tracking the efficiency of sales or marketing processes.
यह उदाहरण मौजूदा प्रस्तुति की पहली स्लाइड में addChart का उपयोग करके एक फ़नल चार्ट जोड़ता है। यह डिफ़ॉल्ट डेटा को छह श्रेणियों और 50 से 500 तक के मानों से बदलता है, फिर अपडेटेड प्रस्तुति को सहेजता है। इनपुट प्रस्तुति में कम से कम एक स्लाइड होना आवश्यक है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation("test.pptx")
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.Funnel, 50, 50, 500, 400)
chart.getChartData().getCategories().clear()
chart.getChartData().getSeries().clear()
workbook = chart.getChartData().getChartDataWorkbook()
workbook.clear(0)
category_cell = workbook.getCell(0, "A1", "Category 1")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A2", "Category 2")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A3", "Category 3")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A4", "Category 4")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A5", "Category 5")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "A6", "Category 6")
chart.getChartData().getCategories().add(category_cell)
series = chart.getChartData().getSeries().add(ChartType.Funnel)
value_cell = workbook.getCell(0, "B1", 50)
series.getDataPoints().addDataPointForFunnelSeries(value_cell)
value_cell = workbook.getCell(0, "B2", 100)
series.getDataPoints().addDataPointForFunnelSeries(value_cell)
value_cell = workbook.getCell(0, "B3", 200)
series.getDataPoints().addDataPointForFunnelSeries(value_cell)
value_cell = workbook.getCell(0, "B4", 300)
series.getDataPoints().addDataPointForFunnelSeries(value_cell)
value_cell = workbook.getCell(0, "B5", 400)
series.getDataPoints().addDataPointForFunnelSeries(value_cell)
value_cell = workbook.getCell(0, "B6", 500)
series.getDataPoints().addDataPointForFunnelSeries(value_cell)
presentation.save("Funnel.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

सनबर्स्ट चार्ट बनाएं
Sunburst charts are used to visualize hierarchical data, displaying levels as concentric rings. They help illustrate part‑to‑whole relationships and are ideal for representing nested categories and subcategories in a clear, compact format.
यह उदाहरण आठ लीव्स को चार स्टेम और दो ब्रांच में समूहित करके एक सनबर्स्ट चार्ट बनाता है। setGroupingItem मेथड स्तर 1 पर स्टेम और स्तर 2 पर ब्रांच असाइन करता है। श्रेणी लेबल खंडों की पहचान करते हैं, और मान उनके सापेक्ष आकार निर्धारित करते हैं।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.Sunburst, 20, 20, 500, 300)
chart.getChartData().getCategories().clear()
chart.getChartData().getSeries().clear()
workbook = chart.getChartData().getChartDataWorkbook()
workbook.clear(0)
# शाखा 1
category_cell = workbook.getCell(0, "C1", "Leaf1")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem1")
leaf.getGroupingLevels().setGroupingItem(2, "Branch1")
category_cell = workbook.getCell(0, "C2", "Leaf2")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "C3", "Leaf3")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem2")
category_cell = workbook.getCell(0, "C4", "Leaf4")
chart.getChartData().getCategories().add(category_cell)
# शाखा 2
category_cell = workbook.getCell(0, "C5", "Leaf5")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem3")
leaf.getGroupingLevels().setGroupingItem(2, "Branch2")
category_cell = workbook.getCell(0, "C6", "Leaf6")
chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "C7", "Leaf7")
leaf = chart.getChartData().getCategories().add(category_cell)
leaf.getGroupingLevels().setGroupingItem(1, "Stem4")
category_cell = workbook.getCell(0, "C8", "Leaf8")
chart.getChartData().getCategories().add(category_cell)
series = chart.getChartData().getSeries().add(ChartType.Sunburst)
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(True)
value_cell = workbook.getCell(0, "D1", 4)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
value_cell = workbook.getCell(0, "D2", 5)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
value_cell = workbook.getCell(0, "D3", 3)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
value_cell = workbook.getCell(0, "D4", 6)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
value_cell = workbook.getCell(0, "D5", 9)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
value_cell = workbook.getCell(0, "D6", 9)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
value_cell = workbook.getCell(0, "D7", 4)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
value_cell = workbook.getCell(0, "D8", 3)
series.getDataPoints().addDataPointForSunburstSeries(value_cell)
presentation.save("Sunburst.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

हिस्टोग्राम चार्ट बनाएं
Histogram charts are used to represent the distribution of numerical data by grouping values into ranges or bins. They are particularly useful for identifying data patterns such as frequency, skewness, and spread, and for detecting outliers in a dataset.
यह उदाहरण छह संख्यात्मक मानों, जिसमें नकारात्मक मान भी शामिल हैं, से एक हिस्टोग्राम बनाता है। setAggregationType को स्वचालित एग्रीगेशन प्रकार के साथ कॉल करने से चार्ट बिन निर्धारित करता है जो वितरण को प्रदर्शित करता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import AxisAggregationType, ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.Histogram, 20, 20, 500, 300)
chart.getChartData().getCategories().clear()
chart.getChartData().getSeries().clear()
workbook = chart.getChartData().getChartDataWorkbook()
workbook.clear(0)
series = chart.getChartData().getSeries().add(ChartType.Histogram)
value_cell = workbook.getCell(0, "A1", 15)
series.getDataPoints().addDataPointForHistogramSeries(value_cell)
value_cell = workbook.getCell(0, "A2", -41)
series.getDataPoints().addDataPointForHistogramSeries(value_cell)
value_cell = workbook.getCell(0, "A3", 16)
series.getDataPoints().addDataPointForHistogramSeries(value_cell)
value_cell = workbook.getCell(0, "A4", 10)
series.getDataPoints().addDataPointForHistogramSeries(value_cell)
value_cell = workbook.getCell(0, "A5", -23)
series.getDataPoints().addDataPointForHistogramSeries(value_cell)
value_cell = workbook.getCell(0, "A6", 16)
series.getDataPoints().addDataPointForHistogramSeries(value_cell)
chart.getAxes().getHorizontalAxis().setAggregationType(AxisAggregationType.Automatic)
presentation.save("Histogram.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

रडार चार्ट बनाएं
Radar charts are used to display multivariate data in a two‑dimensional format, allowing for easy comparison of several variables simultaneously. They are particularly useful for identifying patterns, strengths, and weaknesses across multiple performance metrics or attributes.
यह उदाहरण addChart का उपयोग करके डिफ़ॉल्ट श्रृंखला और श्रेणियों के साथ एक रडार चार्ट बनाता है, फिर प्रस्तुति को PPTX के रूप में सहेजता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
slide.getShapes().addChart(ChartType.Radar, 20, 20, 500, 300)
presentation.save("Radar-chart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

मल्टी‑कैटेगरी चार्ट बनाएं
Multi‑category charts are used to display data that involves more than one categorical grouping, allowing you to compare values across multiple dimensions simultaneously. They are particularly helpful when you need to analyze trends and relationships within complex, multi‑layered datasets.
यह उदाहरण चार जोड़ों में व्यवस्थित आठ श्रेणियों के साथ एक क्लस्टर्ड कॉलम चार्ट बनाता है। setGroupingItem मेथड प्रत्येक जोड़े को समूह स्तर 1 पर एक साझा लेबल देता है, जिससे व्यक्तिगत और समूह लेबल दोनों वाले एक श्रेणी अक्ष बनता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 300)
chart.getChartData().getSeries().clear()
chart.getChartData().getCategories().clear()
workbook = chart.getChartData().getChartDataWorkbook()
workbook.clear(0)
worksheet_index = 0
category_cell = workbook.getCell(0, "c2", "A")
category = chart.getChartData().getCategories().add(category_cell)
category.getGroupingLevels().setGroupingItem(1, "Group1")
category_cell = workbook.getCell(0, "c3", "B")
category = chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "c4", "C")
category = chart.getChartData().getCategories().add(category_cell)
category.getGroupingLevels().setGroupingItem(1, "Group2")
category_cell = workbook.getCell(0, "c5", "D")
category = chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "c6", "E")
category = chart.getChartData().getCategories().add(category_cell)
category.getGroupingLevels().setGroupingItem(1, "Group3")
category_cell = workbook.getCell(0, "c7", "F")
category = chart.getChartData().getCategories().add(category_cell)
category_cell = workbook.getCell(0, "c8", "G")
category = chart.getChartData().getCategories().add(category_cell)
category.getGroupingLevels().setGroupingItem(1, "Group4")
category_cell = workbook.getCell(0, "c9", "H")
category = chart.getChartData().getCategories().add(category_cell)
series_name_cell = workbook.getCell(0, "D1", "Series 1")
series = chart.getChartData().getSeries().add(series_name_cell, ChartType.ClusteredColumn)
value_cell = workbook.getCell(worksheet_index, "D2", 10)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, "D3", 20)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, "D4", 30)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, "D5", 40)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, "D6", 50)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, "D7", 60)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, "D8", 70)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, "D9", 80)
series.getDataPoints().addDataPointForBarSeries(value_cell)
presentation.save("AsposeChart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

मैप चार्ट बनाएं
Map charts are used to visualize geographical data by mapping information to specific locations such as countries, states, or cities. They are particularly useful for analyzing regional trends, demographic data, and spatial distributions in a clear, visually engaging manner.
यह उदाहरण addChart का उपयोग करके डिफ़ॉल्ट भू‑भौगोलिक डेटा के साथ एक मैप चार्ट बनाता है और इसे PowerPoint में देखने हेतु सहेजता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.Map, 20, 20, 500, 300)
presentation.save("mapChart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
परिणाम:

Note
The picture above shows the saved presentation opened in PowerPoint. Aspose.Slides writes the map chart and its data correctly, but it does not draw map charts itself: when a slide holding one is rendered to an image or converted to PDF or SVG, the chart area comes out blank. Other shapes on the same slide are unaffected.कॉम्बिनेशन चार्ट बनाएं
A combination chart (or combo chart) combines two or more chart types in a single graph. This chart lets you highlight, compare, or examine differences between two or more data sets, helping you identify relationships between them.

यह उदाहरण चार क्लस्टर्ड कॉलम श्रृंखलाओं को एक लाइन श्रृंखला के साथ चार श्रेणियों में संयोजित करता है। कॉलम प्राथमिक लम्बवत अक्ष का उपयोग करते हैं, जबकि setPlotOnSecondAxis लाइन को दाएँ ओर दूसरे लम्बवत अक्ष पर रखता है। सहायक फ़ंक्शन शीर्षक, लेजेंड, अक्ष लेबल और ग्रिडलाइन को कॉन्फ़िगर करते हैं।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import AxisPositionType, ChartType, CrossesType, FillType, LegendPositionType, NullableBool, Presentation, SaveFormat
Color = jpype.JClass("java.awt.Color")
def create_combo_chart():
presentation = Presentation()
slide = presentation.getSlides().get_Item(0)
try:
chart = create_chart_with_first_series(slide)
add_second_series_to_chart(chart)
add_third_series_to_chart(chart)
set_primary_axes_format(chart)
set_secondary_axes_format(chart)
presentation.save("combo-chart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
def create_chart_with_first_series(slide):
chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400)
# चार्ट शीर्षक सेट करें।
chart.setTitle(True)
chart.getChartTitle().addTextFrameForOverriding("Chart Title")
chart.getChartTitle().setOverlay(False)
title_paragraph = chart.getChartTitle().getTextFrameForOverriding().getParagraphs().get_Item(0)
title_format = title_paragraph.getParagraphFormat().getDefaultPortionFormat()
title_format.setFontBold(NullableBool.False_)
title_format.setFontHeight(18.0)
# चार्ट लेजेंड सेट करें।
chart.getLegend().setPosition(LegendPositionType.Bottom)
chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(12.0)
# डिफ़ॉल्ट जेनरेटेड सीरीज़ और श्रेणियों को हटाएँ।
chart.getChartData().getSeries().clear()
chart.getChartData().getCategories().clear()
worksheet_index = 0
workbook = chart.getChartData().getChartDataWorkbook()
# नई श्रेणियाँ जोड़ें।
cell = workbook.getCell(worksheet_index, 1, 0, "Category 1")
chart.getChartData().getCategories().add(cell)
cell = workbook.getCell(worksheet_index, 2, 0, "Category 2")
chart.getChartData().getCategories().add(cell)
cell = workbook.getCell(worksheet_index, 3, 0, "Category 3")
chart.getChartData().getCategories().add(cell)
cell = workbook.getCell(worksheet_index, 4, 0, "Category 4")
chart.getChartData().getCategories().add(cell)
# पहली श्रृंखला जोड़ें।
series_name_cell = workbook.getCell(worksheet_index, 0, 1, "Series 1")
series = chart.getChartData().getSeries().add(series_name_cell, chart.getType())
series.getParentSeriesGroup().setOverlap(jpype.JByte(-25))
series.getParentSeriesGroup().setGapWidth(220)
cell = workbook.getCell(worksheet_index, 1, 1, 4.3)
series.getDataPoints().addDataPointForBarSeries(cell)
cell = workbook.getCell(worksheet_index, 2, 1, 2.5)
series.getDataPoints().addDataPointForBarSeries(cell)
cell = workbook.getCell(worksheet_index, 3, 1, 3.5)
series.getDataPoints().addDataPointForBarSeries(cell)
cell = workbook.getCell(worksheet_index, 4, 1, 4.5)
series.getDataPoints().addDataPointForBarSeries(cell)
return chart
def add_second_series_to_chart(chart):
workbook = chart.getChartData().getChartDataWorkbook()
worksheet_index = 0
series_name_cell = workbook.getCell(worksheet_index, 0, 2, "Series 2")
series = chart.getChartData().getSeries().add(series_name_cell, ChartType.ClusteredColumn)
series.getParentSeriesGroup().setOverlap(jpype.JByte(-25))
series.getParentSeriesGroup().setGapWidth(220)
cell = workbook.getCell(worksheet_index, 1, 2, 2.4)
series.getDataPoints().addDataPointForBarSeries(cell)
cell = workbook.getCell(worksheet_index, 2, 2, 4.4)
series.getDataPoints().addDataPointForBarSeries(cell)
cell = workbook.getCell(worksheet_index, 3, 2, 1.8)
series.getDataPoints().addDataPointForBarSeries(cell)
cell = workbook.getCell(worksheet_index, 4, 2, 2.8)
series.getDataPoints().addDataPointForBarSeries(cell)
def add_third_series_to_chart(chart):
workbook = chart.getChartData().getChartDataWorkbook()
worksheet_index = 0
series_name_cell = workbook.getCell(worksheet_index, 0, 3, "Series 3")
series = chart.getChartData().getSeries().add(series_name_cell, ChartType.Line)
cell = workbook.getCell(worksheet_index, 1, 3, 2.0)
series.getDataPoints().addDataPointForLineSeries(cell)
cell = workbook.getCell(worksheet_index, 2, 3, 2.0)
series.getDataPoints().addDataPointForLineSeries(cell)
cell = workbook.getCell(worksheet_index, 3, 3, 3.0)
series.getDataPoints().addDataPointForLineSeries(cell)
cell = workbook.getCell(worksheet_index, 4, 3, 5.0)
series.getDataPoints().addDataPointForLineSeries(cell)
series.setPlotOnSecondAxis(True)
def set_primary_axes_format(chart):
# क्षैतिज अक्ष सेट करें।
horizontal_axis = chart.getAxes().getHorizontalAxis()
horizontal_axis.getTextFormat().getPortionFormat().setFontHeight(12.0)
horizontal_axis.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
set_axis_title(horizontal_axis, "X Axis")
# लंबवत अक्ष सेट करें।
vertical_axis = chart.getAxes().getVerticalAxis()
vertical_axis.getTextFormat().getPortionFormat().setFontHeight(12.0)
vertical_axis.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
set_axis_title(vertical_axis, "Y Axis 1")
# लंबवत प्रमुख ग्रिडलाइन का रंग सेट करें।
major_grid_lines_format = vertical_axis.getMajorGridLinesFormat().getLine().getFillFormat()
major_grid_lines_format.setFillType(FillType.Solid)
color = Color(217, 217, 217)
major_grid_lines_format.getSolidFillColor().setColor(color)
def set_secondary_axes_format(chart):
# द्वितीयक क्षैतिज अक्ष सेट करें।
secondary_horizontal_axis = chart.getAxes().getSecondaryHorizontalAxis()
secondary_horizontal_axis.setPosition(AxisPositionType.Bottom)
secondary_horizontal_axis.setCrossType(CrossesType.Maximum)
secondary_horizontal_axis.setVisible(False)
secondary_horizontal_axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
secondary_horizontal_axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
# द्वितीयक लंबवत अक्ष सेट करें।
secondary_vertical_axis = chart.getAxes().getSecondaryVerticalAxis()
secondary_vertical_axis.setPosition(AxisPositionType.Right)
secondary_vertical_axis.getTextFormat().getPortionFormat().setFontHeight(12.0)
secondary_vertical_axis.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
secondary_vertical_axis.getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
secondary_vertical_axis.getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill)
set_axis_title(secondary_vertical_axis, "Y Axis 2")
def set_axis_title(axis, axis_title):
axis.setTitle(True)
axis.getTitle().setOverlay(False)
title_paragraph = axis.getTitle().addTextFrameForOverriding(axis_title).getParagraphs().get_Item(0)
title_format = title_paragraph.getParagraphFormat().getDefaultPortionFormat()
title_format.setFontBold(NullableBool.False_)
title_format.setFontHeight(12.0)
create_combo_chart()
चार्ट अपडेट करें
Aspose.Slides for Python via Java enables you to update PowerPoint charts by modifying chart data, formatting, and styling. This functionality simplifies the process of keeping presentations up-to-date with dynamic content and ensures that charts accurately reflect current data and visual standards.
यह उदाहरण मौजूदा प्रस्तुति की पहली स्लाइड पर “My chart” नामक चार्ट को अपडेट करता है। इसमें तीन डेटा पॉइंट प्रत्येक वाली दो कॉलम श्रृंखलाएँ आवश्यक हैं, जिसमें कॉलम A में श्रेणी लेबल और प्रथम कार्यपत्रिका की पहली पंक्ति में श्रृंखला नाम होते हैं। उदाहरण getCell का उपयोग करके वर्कबुक सेल्स बदलता है, श्रृंखला मान अपडेट करता है, तीसरी श्रृंखला जोड़ता है, और setType के माध्यम से चार्ट को क्लस्टर्ड सिलेंडर में बदलता है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Chart, ChartType, Presentation, SaveFormat
chart_name = "My chart"
presentation = Presentation("ExistingChart.pptx")
try:
slide = presentation.getSlides().get_Item(0)
for shape in slide.getShapes():
if isinstance(shape, Chart) and chart_name == shape.getName():
chart = shape
worksheet_index = 0
workbook = chart.getChartData().getChartDataWorkbook()
workbook.getCell(worksheet_index, 1, 0, "Modified Category 1")
workbook.getCell(worksheet_index, 2, 0, "Modified Category 2")
series = chart.getChartData().getSeries().get_Item(0)
workbook.getCell(worksheet_index, 0, 1, "New_Series 1")
series.getDataPoints().get_Item(0).getValue().setData(90)
series.getDataPoints().get_Item(1).getValue().setData(123)
series.getDataPoints().get_Item(2).getValue().setData(44)
series = chart.getChartData().getSeries().get_Item(1)
workbook.getCell(worksheet_index, 0, 2, "New_Series 2")
series.getDataPoints().get_Item(0).getValue().setData(23)
series.getDataPoints().get_Item(1).getValue().setData(67)
series.getDataPoints().get_Item(2).getValue().setData(99)
series_name_cell = workbook.getCell(worksheet_index, 0, 3, "Series 3")
series = chart.getChartData().getSeries().add(series_name_cell, chart.getType())
value_cell = workbook.getCell(worksheet_index, 1, 3, 20)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 2, 3, 50)
series.getDataPoints().addDataPointForBarSeries(value_cell)
value_cell = workbook.getCell(worksheet_index, 3, 3, 30)
series.getDataPoints().addDataPointForBarSeries(value_cell)
chart.setType(ChartType.ClusteredCylinder)
presentation.save("AsposeChartModified.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
चार्ट के लिए डेटा रेंज सेट करें
To inspect the range already used by an existing chart, see Retrieve a Chart’s Data Range.
Aspose.Slides for Python via Java provides the flexibility to define a specific data range from a worksheet as the source for your chart’s data. This means you can directly map a portion of your worksheet to the chart, allowing you to control which cells contribute to the chart’s series and categories. As a result, you can easily update and synchronize your charts with the latest data changes in your worksheet, ensuring that your PowerPoint presentations reflect current and accurate information.
यह उदाहरण setRange का उपयोग करके मौजूदा प्रस्तुति की पहली स्लाइड पर “My chart” नामक चार्ट के डेटा स्रोत को Sheet1!A1:B4 पर सेट करता है। चार्ट वर्कबुक में वह कार्यपत्रिका और प्रविष्ट रेंज होनी चाहिए जिसमें पहली पंक्ति में श्रृंखला शीर्षक, कॉलम A में श्रेणी लेबल और कॉलम B में तीन मान हों।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Chart, Presentation, SaveFormat
chart_name = "My chart"
presentation = Presentation("ExistingChart.pptx")
try:
slide = presentation.getSlides().get_Item(0)
for shape in slide.getShapes():
if isinstance(shape, Chart) and chart_name == shape.getName():
chart = shape
chart.getChartData().setRange("Sheet1!A1:B4")
presentation.save("SetDataRange.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
चार्ट में डिफ़ॉल्ट मार्कर उपयोग करें
When you use default markers in charts, each chart series gets a different default marker symbol automatically.
यह उदाहरण addChart का उपयोग करके दो लाइन श्रृंखलाओं और एक लेजेंड के साथ चार्ट बनाता है। getMarker द्वारा एक्सेस किए गए मार्कर सेटिंग्स स्वतः असाइन किए गए मार्कर प्रतीकों को बरकरार रखते हैं। पहली श्रृंखला में एक नकारात्मक मान और एक अनुपस्थित मान (None) है, जबकि दूसरी में प्रत्येक श्रेणी के लिए मान है।
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import ChartType, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 10, 10, 400, 400)
chart.getChartData().getSeries().clear()
chart.getChartData().getCategories().clear()
workbook = chart.getChartData().getChartDataWorkbook()
series_name_cell = workbook.getCell(0, 0, 1, "Series 1")
series = chart.getChartData().getSeries().add(series_name_cell, chart.getType())
category_cell = workbook.getCell(0, 1, 0, "C1")
chart.getChartData().getCategories().add(category_cell)
value_cell = workbook.getCell(0, 1, 1, 24)
series.getDataPoints().addDataPointForLineSeries(value_cell)
category_cell = workbook.getCell(0, 2, 0, "C2")
chart.getChartData().getCategories().add(category_cell)
value_cell = workbook.getCell(0, 2, 1, 23)
series.getDataPoints().addDataPointForLineSeries(value_cell)
category_cell = workbook.getCell(0, 3, 0, "C3")
chart.getChartData().getCategories().add(category_cell)
value_cell = workbook.getCell(0, 3, 1, -10)
series.getDataPoints().addDataPointForLineSeries(value_cell)
category_cell = workbook.getCell(0, 4, 0, "C4")
chart.getChartData().getCategories().add(category_cell)
value_cell = workbook.getCell(0, 4, 1, None)
series.getDataPoints().addDataPointForLineSeries(value_cell)
series_name_cell = workbook.getCell(0, 0, 2, "Series 2")
second_series = chart.getChartData().getSeries().add(series_name_cell, chart.getType())
value_cell = workbook.getCell(0, 1, 2, 30)
second_series.getDataPoints().addDataPointForLineSeries(value_cell)
value_cell = workbook.getCell(0, 2, 2, 10)
second_series.getDataPoints().addDataPointForLineSeries(value_cell)
value_cell = workbook.getCell(0, 3, 2, 60)
second_series.getDataPoints().addDataPointForLineSeries(value_cell)
value_cell = workbook.getCell(0, 4, 2, 40)
second_series.getDataPoints().addDataPointForLineSeries(value_cell)
chart.setLegend(True)
chart.getLegend().setOverlay(False)
presentation.save("DefaultMarkersInChart.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
FAQ
Aspose.Slides for Python via Java द्वारा कौन से चार्ट प्रकार समर्थित हैं?
Aspose.Slides for Python via Java विभिन्न प्रकार के चार्ट प्रकारों का समर्थन करता है, जिसमें बार, लाइन, पाई, एरिया, स्कैटर, हिस्टोग्राम, रडार और कई अन्य शामिल हैं। यह लचीलापन आपको अपने डेटा विज़ुअलाइज़ेशन आवश्यकताओं के लिए सबसे उपयुक्त चार्ट प्रकार चुनने की अनुमति देता है।
मैं स्लाइड में नया चार्ट कैसे जोड़ूं?
एक चार्ट जोड़ने के लिए, आप पहले Presentation क्लास की एक इंस्टेंस बनाते हैं, उसका इच्छित स्लाइड इंडेक्स प्राप्त करते हैं, और फिर चार्ट जोड़ने के लिए मेथड कॉल करते हैं, जिसमें चार्ट प्रकार और प्रारंभिक डेटा निर्दिष्ट किया जाता है। यह प्रक्रिया चार्ट को सीधे आपकी प्रस्तुति में एकीकृत करती है।
मैं चार्ट में प्रदर्शित डेटा को कैसे अपडेट कर सकता हूँ?
आप ChartDataWorkbook तक पहुंचकर, किसी भी डिफ़ॉल्ट श्रृंखला और श्रेणियों को साफ़ करके, और अपनी कस्टम डेटा जोड़कर चार्ट के डेटा को अपडेट कर सकते हैं। यह आपको प्रोग्रामेटिक रूप से चार्ट को नवीनतम डेटा के साथ ताज़ा करने की अनुमति देता है।
क्या मैं चार्ट की उपस्थिति को अनुकूलित कर सकता हूँ?
हाँ, Aspose.Slides for Python via Java व्यापक अनुकूलन विकल्प प्रदान करता है। आप रंग, फ़ॉन्ट, लेबल, लेजेंड और अन्य फ़ॉर्मेटिंग तत्वों को संशोधित करके चार्ट की उपस्थिति को अपने विशिष्ट डिज़ाइन आवश्यकताओं के अनुसार ढाल सकते हैं।