ضبط مظهر الرسم البياني

ضبط مظهر الرسم البياني

في كيفية إنشاء مخطط قدمنا ​​مقدمة موجزة لأنواع المخططات والكائنات الخاصة بها المعروضة في أسبوست كيلز للبايثون via .NET، ووصفنا كيفية إنشائها. تناقش هذه المقالة كيفية تخصيص مظهر المخططات بضبط خصائصها:

  • تعيين منطقة الرسم البياني.
  • تعيين خطوط الرسم البياني.
  • تطبيق السمات.
  • تعيين عناوين للرسوم البيانية والمحاور.
  • العمل مع خطوط الشبكة.

تعيين منطقة الرسم البياني

هناك أنواع مختلفة من المناطق في مخطط ويوفر أسبوست كيلز للبايثون via .NET مرونة لتعديل مظهر كل منطقة. يمكن للمطورين تطبيق إعدادات تنسيق مختلفة على منطقة من خلال تغيير لون المقدمة، لون الخلفية، وتنسيق التعبئة وغيرها.

في المثال الوارد أدناه، قمنا بتطبيق إعدادات تنسيق مختلفة على أنواع مختلفة من المناطق في رسم بياني. هذه المناطق تشمل:

  • منطقة الرسم
  • منطقة الرسم البياني
  • منطقة مجموعات السلاسل
  • منطقة نقطة واحدة في مجموعة سلاسل

الكود البرمجي التالي يوضح كيفية ضبط منطقة الرسم البياني.

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import GradientStyleType
from aspose.pydrawing import Color
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Workbook object
sheetIndex = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[sheetIndex]
# Adding sample values to cells
worksheet.cells.get("A1").put_value(50)
worksheet.cells.get("A2").put_value(100)
worksheet.cells.get("A3").put_value(150)
worksheet.cells.get("B1").put_value(60)
worksheet.cells.get("B2").put_value(32)
worksheet.cells.get("B3").put_value(50)
# Adding a chart to the worksheet
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5)
# Accessing the instance of the newly added chart
chart = worksheet.charts[chartIndex]
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.n_series.add("A1:B3", True)
# Setting the foreground color of the plot area
chart.plot_area.area.foreground_color = Color.blue
# Setting the foreground color of the chart area
chart.chart_area.area.foreground_color = Color.yellow
# Setting the foreground color of the 1st SeriesCollection area
chart.n_series[0].area.foreground_color = Color.red
# Setting the foreground color of the area of the 1st SeriesCollection point
chart.n_series[0].points[0].area.foreground_color = Color.cyan
# Filling the area of the 2nd SeriesCollection with a gradient
chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")

تعيين خطوط الرسم البياني

يمكن للمطورين أيضًا تطبيق أنواع مختلفة من الأنماط على الخطوط أو علامات البيانات في SeriesCollection. يُظهر الكود التالي كيفية تعيين خطوط المخطط باستخدام واجهة برمجة تطبيقات أسبوست كيلز للبايثون via .NET.

from aspose.cells import Workbook
from aspose.cells.charts import ChartMarkerType, ChartType
from aspose.cells.drawing import GradientStyleType, LineType, WeightType
from aspose.pydrawing import Color
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Workbook object
sheetIndex = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[sheetIndex]
# Adding sample values to cells
worksheet.cells.get("A1").put_value(50)
worksheet.cells.get("A2").put_value(100)
worksheet.cells.get("A3").put_value(150)
worksheet.cells.get("B1").put_value(60)
worksheet.cells.get("B2").put_value(32)
worksheet.cells.get("B3").put_value(50)
# Adding a chart to the worksheet
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5)
# Accessing the instance of the newly added chart
chart = worksheet.charts[chartIndex]
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.n_series.add("A1:B3", True)
# Setting the foreground color of the plot area
chart.plot_area.area.foreground_color = Color.blue
# Setting the foreground color of the chart area
chart.chart_area.area.foreground_color = Color.yellow
# Setting the foreground color of the 1st SeriesCollection area
chart.n_series[0].area.foreground_color = Color.red
# Setting the foreground color of the area of the 1st SeriesCollection point
chart.n_series[0].points[0].area.foreground_color = Color.cyan
# Filling the area of the 2nd SeriesCollection with a gradient
chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1)
# Applying a dotted line style on the lines of a SeriesCollection
chart.n_series[0].border.style = LineType.DOT
# Applying a triangular marker style on the data markers of a SeriesCollection
chart.n_series[0].marker.marker_style = ChartMarkerType.TRIANGLE
# Setting the weight of all lines in a SeriesCollection to medium
chart.n_series[1].border.weight = WeightType.MEDIUM_LINE
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")

تطبيق سمات مايكروسوفت اكسيل 2007/2010 على الرسوم البيانية

يمكن للمطورين تطبيق سمات/ألوان مايكروسوفت إكسل مختلفة على SeriesCollection أو كائنات مخططات أخرى كما هو موضح في المثال أدناه.

from aspose.cells import ThemeColor, ThemeColorType, Workbook
from aspose.cells.drawing import FillType
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate the workbook to open the file that contains a chart
workbook = Workbook(dataDir + "book1.xlsx")
# Get the first worksheet
worksheet = workbook.worksheets[1]
# Get the first chart in the sheet
chart = worksheet.charts[0]
# Specify the FilFormat's type to Solid Fill of the first series
chart.n_series[0].area.fill_format.fill_type = FillType.SOLID
# Get the CellsColor of SolidFill
cc = chart.n_series[0].area.fill_format.solid_fill.cells_color
# Create a theme in Accent style
cc.theme_color = ThemeColor(ThemeColorType.ACCENT6, 0.6)
# Apply the them to the series
chart.n_series[0].area.fill_format.solid_fill.cells_color = cc
# Save the Excel file
workbook.save(dataDir + "output.out.xlsx")

ضبط عناوين الرسوم البيانية أو المحاور

يمكنك استخدام مايكروسوفت إكسل لتعيين عناوين المخطط ومحاورها في بيئة WYSIWYG. يسمح أسبوست كيلز للبايثون via .NET أيضًا للمطورين بضبط عناوين المخطط ومحورته في وقت التشغيل. تحتوي جميع المخططات ومحاورها على خاصية Chart.title التي يمكن استخدامها لضبط عناوينها كما هو موضح أدناه في مثال.

يوضح مقتطف الكود التالي كيفية ضبط عناوين الرسوم البيانية والمحاور.

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import GradientStyleType
from aspose.pydrawing import Color
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Workbook object
sheetIndex = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[sheetIndex]
# Adding sample values to cells
worksheet.cells.get("A1").put_value(50)
worksheet.cells.get("A2").put_value(100)
worksheet.cells.get("A3").put_value(150)
worksheet.cells.get("B1").put_value(60)
worksheet.cells.get("B2").put_value(32)
worksheet.cells.get("B3").put_value(50)
# Adding a chart to the worksheet
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5)
# Accessing the instance of the newly added chart
chart = worksheet.charts[chartIndex]
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.n_series.add("A1:B3", True)
# Setting the foreground color of the plot area
chart.plot_area.area.foreground_color = Color.blue
# Setting the foreground color of the chart area
chart.chart_area.area.foreground_color = Color.yellow
# Setting the foreground color of the 1st SeriesCollection area
chart.n_series[0].area.foreground_color = Color.red
# Setting the foreground color of the area of the 1st SeriesCollection point
chart.n_series[0].points[0].area.foreground_color = Color.cyan
# Filling the area of the 2nd SeriesCollection with a gradient
chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1)
# Setting the title of a chart
chart.title.text = "Title"
# Setting the font color of the chart title to blue
chart.title.font.color = Color.blue
# Setting the title of category axis of the chart
chart.category_axis.title.text = "Category"
# Setting the title of value axis of the chart
chart.value_axis.title.text = "Value"
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")

العمل مع خطوط الشبكة الرئيسية

من الممكن تخصيص شكل خطوط الشبكة الرئيسية. يمكن إخفاء أو إظهار خطوط الشبكة أو تحديد لونها وإعدادات أخرى. فيما يلي، نُوضّح كيفية إخفاء خطوط الشبكة وكيفية تغيير لونها.

إخفاء خطوط الشبكة الرئيسية

يمكن للمطورين التحكم في ظهور الخطوط الشبكية الكبرى من خلال ضبط خاصية is_visible الخاصة بكائن Line على true أو false.

الكود البرمجي التالي يوضح كيفية إخفاء خطوط الشبكة الرئيسية. بعد إخفاء خطوط الشبكة الرئيسية، سيتم إضافة رسم بياني للأعمدة إلى ورقة العمل بدون خطوط شبكة.

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import GradientStyleType
from aspose.pydrawing import Color
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Workbook object
sheetIndex = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[sheetIndex]
# Adding sample values to cells
worksheet.cells.get("A1").put_value(50)
worksheet.cells.get("A2").put_value(100)
worksheet.cells.get("A3").put_value(150)
worksheet.cells.get("B1").put_value(60)
worksheet.cells.get("B2").put_value(32)
worksheet.cells.get("B3").put_value(50)
# Adding a chart to the worksheet
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5)
# Accessing the instance of the newly added chart
chart = worksheet.charts[chartIndex]
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.n_series.add("A1:B3", True)
# Setting the foreground color of the plot area
chart.plot_area.area.foreground_color = Color.blue
# Setting the foreground color of the chart area
chart.chart_area.area.foreground_color = Color.yellow
# Setting the foreground color of the 1st SeriesCollection area
chart.n_series[0].area.foreground_color = Color.red
# Setting the foreground color of the area of the 1st SeriesCollection point
chart.n_series[0].points[0].area.foreground_color = Color.cyan
# Filling the area of the 2nd SeriesCollection with a gradient
chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1)
# Hiding the major gridlines of Category Axis
chart.category_axis.major_grid_lines.is_visible = False
# Hiding the major gridlines of Value Axis
chart.value_axis.major_grid_lines.is_visible = False
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")

تغيير إعدادات خطوط الشبكة الرئيسية

لا يستطيع المطورون فقط التحكم في رؤية خطوط الشبكة الرئيسية ولكن أيضًا خصائص أخرى بما في ذلك لونها وما إلى ذلك.

الكود البرمجي التالي يوضح كيفية تغيير لون خطوط الشبكة الرئيسية. بعد تعيين لون خطوط الشبكة الرئيسية، سيتم إضافة رسم بياني للأعمدة إلى ورقة العمل بخطوط شبكة معدلة.

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import GradientStyleType
from aspose.pydrawing import Color
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Workbook object
sheetIndex = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[sheetIndex]
# Adding sample values to cells
worksheet.cells.get("A1").put_value(50)
worksheet.cells.get("A2").put_value(100)
worksheet.cells.get("A3").put_value(150)
worksheet.cells.get("B1").put_value(60)
worksheet.cells.get("B2").put_value(32)
worksheet.cells.get("B3").put_value(50)
# Adding a chart to the worksheet
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5)
# Accessing the instance of the newly added chart
chart = worksheet.charts[chartIndex]
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.n_series.add("A1:B3", True)
# Setting the foreground color of the plot area
chart.plot_area.area.foreground_color = Color.blue
# Setting the foreground color of the chart area
chart.chart_area.area.foreground_color = Color.yellow
# Setting the foreground color of the 1st SeriesCollection area
chart.n_series[0].area.foreground_color = Color.red
# Setting the foreground color of the area of the 1st SeriesCollection point
chart.n_series[0].points[0].area.foreground_color = Color.cyan
# Filling the area of the 2nd SeriesCollection with a gradient
chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1)
# Setting the color of Category Axis' major gridlines to silver
chart.category_axis.major_grid_lines.color = Color.silver
# Setting the color of Value Axis' major gridlines to red
chart.value_axis.major_grid_lines.color = Color.red
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")

مواضيع متقدمة