XLSX: Работа с диаграммами на странице XLSX
В этом разделе
UI-контролы
SpreadsheetEditorControl и
WpfSpreadsheetEditorControl позволяют работать (просматривать, добавлять, редактировать и удалять) с диаграммами на рабочем листе XLSX в настольном приложении (WinForms, WPF).
Диаграммы можно изменять визуально с помощью мыши/клавиатуры или программно.
Список поддерживаемых стандартных типов диаграмм
Вот список стандартных типов диаграмм, которые поддерживаются SDK:
-
Столбчатые диаграммы:
- Clustered Column
- Stacked Column
- 100% Stacked Column
- 3D Clustered Column
- 3D Stacked Column
- 3D 100% Stacked Column
- 3D Column
-
Линейные диаграммы:
- Line
- Stacked Line
- 100% Stacked Line
- Line with Markers
- Stacked Line with Markers
- 100% Stacked Line with Markers
- 3D Line
-
Круговые диаграммы:
- Круговая диаграмма
- Объемная круговая
- Пончиковая диаграмма
-
Bar charts:
- Clustered Bar
- Stacked Bar
- 100% Stacked Bar
- 3D Clustered Bar
- 3D Stacked Bar
- 3D 100% Stacked Bar
-
Диаграммы с областями:
- Area
- Stacked Area
- 100% Stacked Area
- 3D Area
- 3D Stacked Area
- 3D 100% Stacked Area
-
X Y (Scatter):
- Scatter
- Scatter with Smooth Lines and Markers
- Scatter with Smooth Lines
- Scatter with Straight Lines and Markers
- Scatter with Straight Lines
- Bubble
- 3D Bubble
-
Stock:
- High-Low-Close
- Open-High-Low-Close
- Volume-High-Low-Close
- Volume-Open-High-Low-Close
-
Поверхностная:
- Объёмная поверхностная
- Бесцветная объёмная поверхностная
-
Лепестковая:
- Лепестковая
- Лепестковая с маркерами
- Заполненная лепестковая
-
Combo:
- Пользовательская комбинация
Добавление новой диаграммы на лист XLSX
Если вы хотите добавить новую диаграмму, вам необходимо предоставить существующую диаграмму в качестве шаблона для новой диаграммы.
Вот C#/VB.NET код, который демонстрирует, как добавить столбчатую диаграмму на сфокусированный рабочий лист XLSX:
/// <summary>
/// Adds the chart to a worksheet.
/// </summary>
/// <param name="editorControl">The spreadsheet editor control.</param>
/// <param name="templateFilePath">A name of file that contains templates of charts.</param>
/// <param name="worksheetIndex">A zero-based index of the worksheet that contains the chart.</param>
/// <param name="chartIndex">A zero-based index of the chart that should be added.</param>
public void AddChartToXlsxWorksheet(
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl,
string chartTemplateFileName,
int worksheetIndex,
int chartIndex)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// open XLSX file that contains template chart
using (Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditorSource templateSource =
new Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditorSource(chartTemplateFileName))
{
// create the editor for template XLSX file
using (Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditor templateSourceEditor =
new Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditor(templateSource, false))
{
// initialize the editor
templateSourceEditor.Initialize(new Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditorSettings());
// get worksheet by worksheet index
Vintasoft.Imaging.Office.Spreadsheet.Document.Worksheet worksheet = templateSourceEditor.Document.Worksheets[worksheetIndex];
// get the template chart by chart index
Vintasoft.Imaging.Office.Spreadsheet.Document.SheetDrawing templateChart = worksheet.Drawings[chartIndex];
// add new chart that is based on template chart
spreadsheetVisualEditor.AddChart(worksheet, templateChart);
}
}
}
''' <summary>
''' Adds the chart to a worksheet.
''' </summary>
''' <param name="editorControl">The spreadsheet editor control.</param>
''' <param name="templateFilePath">A name of file that contains templates of charts.</param>
''' <param name="worksheetIndex">A zero-based index of the worksheet that contains the chart.</param>
''' <param name="chartIndex">A zero-based index of the chart that should be added.</param>
Public Sub AddChartToXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl, chartTemplateFileName As String, worksheetIndex As Integer, chartIndex As Integer)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' open XLSX file that contains template chart
Using templateSource As New Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditorSource(chartTemplateFileName)
' create the editor for template XLSX file
Using templateSourceEditor As New Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditor(templateSource, False)
' initialize the editor
templateSourceEditor.Initialize(New Vintasoft.Imaging.Office.Spreadsheet.SpreadsheetEditorSettings())
' get worksheet by worksheet index
Dim worksheet As Vintasoft.Imaging.Office.Spreadsheet.Document.Worksheet = templateSourceEditor.Document.Worksheets(worksheetIndex)
' get the template chart by chart index
Dim templateChart As Vintasoft.Imaging.Office.Spreadsheet.Document.SheetDrawing = worksheet.Drawings(chartIndex)
' add new chart that is based on template chart
spreadsheetVisualEditor.AddChart(worksheet, templateChart)
End Using
End Using
End Sub
Данные диаграммы: Установите данные серии диаграммы
Если вы хотите установить данные серии для диаграммы с помощью мыши, вам следует выполнить следующие шаги:
- Нажмите на диаграмму, которую необходимо изменить, и редактор выделит ячейки, представляющие данные диаграммы. Выбранные ячейки будут выделены синей областью выделения.
- Изменить размер или переместить синюю область выделения, если вы хотите изменить ячейки, представляющие данные диаграммы.
Данные диаграммы: Установка данных категории для диаграммы
Если вы хотите установить данные категории для диаграммы с помощью мыши, вам следует выполнить следующие шаги:
- Нажать на диаграмму, которую необходимо изменить, и редактор выделит ячейки, представляющие данные категории, используя красную область выделения.
- Изменить размер или переместить красную область выделения, если вы хотите изменить ячейки, которые представляют данные категории.
Вид диаграммы: Установка меток осей для диаграммы
Если вы хотите установить метки осей для диаграммы с помощью мыши, вам следует выполнить следующие шаги:
- Нажать на диаграмму, которую следует изменить, и редактор выделит ячейки, которые представляют собой метки осей. Выбранные ячейки будут выделены фиолетовой областью выделения.
- Изменить размер или переместить фиолетовую область выделения, если вы хотите изменить ячейки, представляющие метки осей.
Данные диаграммы: Установка данных диаграммы (серии, категории, метки осей) для диаграммы.
Вот C#/VB.NET код, который демонстрирует, как изменить данные диаграммы для диаграммы на листе XLSX:
/// <summary>
/// Changes the chart data (categories name, series name and series values) for chart in SalesReport.xlsx file.
/// </summary>
/// <param name="editorControl">The spreadsheet editor control.</param>
public void SetDataOfXlsxChart(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// create worksheet editor
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor worksheetEditor =
spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet);
try
{
// create editor for focused chart
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor chartEditor =
worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing);
// create editor for chart properties
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor chartPropertiesEditor =
chartEditor.CreateChartPropertiesEditor();
// create the cell references, which reference cells region "D6:F6" as cells for data of chart categories
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences categoriesReferences =
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.CreateFixedReferences(
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Parse("D6:F6"),
spreadsheetVisualEditor.FocusedWorksheet.Name,
true, true);
// create the cell references, which reference cells region "C7:C10" as cells for data of chart series
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences seriesReferences =
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.CreateFixedReferences(
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Parse("C7:C10"),
spreadsheetVisualEditor.FocusedWorksheet.Name,
true, true);
// create the cell references, which reference cells region "D7:F10" as cells for data of chart series data
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences seriesDataReferences =
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.CreateFixedReferences(
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Parse("D7:F10"),
spreadsheetVisualEditor.FocusedWorksheet.Name,
true, true);
// union all references
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences references =
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Union(categoriesReferences,
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Union(seriesReferences, seriesDataReferences));
// set data references for chart
chartPropertiesEditor.SetDataReferences(references);
}
finally
{
spreadsheetVisualEditor.Editor.FinishEditing();
}
}
''' <summary>
''' Changes the chart data (categories name, series name and series values) for chart in SalesReport.xlsx file.
''' </summary>
''' <param name="editorControl">The spreadsheet editor control.</param>
Public Sub SetDataOfXlsxChart(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' create worksheet editor
Dim worksheetEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor = spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet)
Try
' create editor for focused chart
Dim chartEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor = worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing)
' create editor for chart properties
Dim chartPropertiesEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor = chartEditor.CreateChartPropertiesEditor()
' create the cell references, which reference cells region "D6:F6" as cells for data of chart categories
Dim categoriesReferences As Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences = Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.CreateFixedReferences(Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Parse("D6:F6"), spreadsheetVisualEditor.FocusedWorksheet.Name, True, True)
' create the cell references, which reference cells region "C7:C10" as cells for data of chart series
Dim seriesReferences As Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences = Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.CreateFixedReferences(Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Parse("C7:C10"), spreadsheetVisualEditor.FocusedWorksheet.Name, True, True)
' create the cell references, which reference cells region "D7:F10" as cells for data of chart series data
Dim seriesDataReferences As Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences = Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.CreateFixedReferences(Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Parse("D7:F10"), spreadsheetVisualEditor.FocusedWorksheet.Name, True, True)
' union all references
Dim references As Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences = Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Union(categoriesReferences, Vintasoft.Imaging.Office.Spreadsheet.Document.CellReferences.Union(seriesReferences, seriesDataReferences))
' set data references for chart
chartPropertiesEditor.SetDataReferences(references)
Finally
spreadsheetVisualEditor.Editor.FinishEditing()
End Try
End Sub
Вид диаграммы: Установка заголовка диаграммы
Вот C#/VB.NET код, который демонстрирует, как установить текст и шрифт заголовок диаграммы:
/// <summary>
/// Sets the chart title and font properties.
/// </summary>
/// <param name="editorControl">The spreadsheet editor control.</param>
/// <param name="fontProperties">The title font properties.</param>
/// <param name="title">The title text.</param>
public void SetTitleOfXlsxChart(
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl,
Vintasoft.Imaging.Office.Spreadsheet.Document.FontProperties fontProperties,
string title)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// create worksheet editor
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor worksheetEditor =
spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet);
try
{
// create editor for focused chart
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor chartEditor =
worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing);
// create editor for chart properties
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor chartPropertiesEditor =
chartEditor.CreateChartPropertiesEditor();
// set title of the chart
chartPropertiesEditor.SetTitle(title);
// create the text appearance
Vintasoft.Imaging.Office.Spreadsheet.Document.TextAppearance textAppearance = new Vintasoft.Imaging.Office.Spreadsheet.Document.TextAppearance(
fontProperties,
new Vintasoft.Imaging.Office.Spreadsheet.Document.TextProperties());
// create the text and shape appearance
Vintasoft.Imaging.Office.Spreadsheet.Document.TextShapeAppearance appearance = new Vintasoft.Imaging.Office.Spreadsheet.Document.TextShapeAppearance(
textAppearance,
chartPropertiesEditor.ChartProperties.TitleAppearance.ShapeAppearance);
chartPropertiesEditor.SetTitleAppearance(appearance);
}
finally
{
spreadsheetVisualEditor.Editor.FinishEditing();
}
}
''' <summary>
''' Sets the chart title and font properties.
''' </summary>
''' <param name="editorControl">The spreadsheet editor control.</param>
''' <param name="fontProperties">The title font properties.</param>
''' <param name="title">The title text.</param>
Public Sub SetTitleOfXlsxChart(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl, fontProperties As Vintasoft.Imaging.Office.Spreadsheet.Document.FontProperties, title As String)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' create worksheet editor
Dim worksheetEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor = spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet)
Try
' create editor for focused chart
Dim chartEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor = worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing)
' create editor for chart properties
Dim chartPropertiesEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor = chartEditor.CreateChartPropertiesEditor()
' set title of the chart
chartPropertiesEditor.SetTitle(title)
' create the text appearance
Dim textAppearance As New Vintasoft.Imaging.Office.Spreadsheet.Document.TextAppearance(fontProperties, New Vintasoft.Imaging.Office.Spreadsheet.Document.TextProperties())
' create the text and shape appearance
Dim appearance As New Vintasoft.Imaging.Office.Spreadsheet.Document.TextShapeAppearance(textAppearance, chartPropertiesEditor.ChartProperties.TitleAppearance.ShapeAppearance)
chartPropertiesEditor.SetTitleAppearance(appearance)
Finally
spreadsheetVisualEditor.Editor.FinishEditing()
End Try
End Sub
Вид диаграммы: Установка цвета области графика и области диаграммы
Вот C#/VB.NET код, который демонстрирует, как установить цвет области графика и области диаграммы:
/// <summary>
/// Sets the chart background color and the plot area background color.
/// </summary>
/// <param name="editorControl">The spreadsheet editor control.</param>
/// <param name="chartBackgroundColor">The chart background color.</param>
/// <param name="plotAreaBackgroundColor">The plot area background color.</param>
public void SetColorForPlotAndChartAreaOfXlsxChart(
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl,
Vintasoft.Primitives.VintasoftColor chartBackgroundColor,
Vintasoft.Primitives.VintasoftColor plotAreaBackgroundColor)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// create worksheet editor
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor worksheetEditor =
spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet);
try
{
// create editor for focused chart
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor chartEditor =
worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing);
// create editor for chart properties
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor chartPropertiesEditor =
chartEditor.CreateChartPropertiesEditor();
// set the chart appearance
chartPropertiesEditor.SetChartAreaAppearance(new Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(
chartBackgroundColor,
chartPropertiesEditor.ChartProperties.ChartAreaAppearance.OutlineColor,
chartPropertiesEditor.ChartProperties.ChartAreaAppearance.OutlineWidth));
// set the plot area appearance
chartPropertiesEditor.SetPlotAreaAppearance(new Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(
plotAreaBackgroundColor,
chartPropertiesEditor.ChartProperties.PlotAreaAppearance.OutlineColor,
chartPropertiesEditor.ChartProperties.PlotAreaAppearance.OutlineWidth));
}
finally
{
spreadsheetVisualEditor.Editor.FinishEditing();
}
}
''' <summary>
''' Sets the chart background color and the plot area background color.
''' </summary>
''' <param name="editorControl">The spreadsheet editor control.</param>
''' <param name="chartBackgroundColor">The chart background color.</param>
''' <param name="plotAreaBackgroundColor">The plot area background color.</param>
Public Sub SetColorForPlotAndChartAreaOfXlsxChart(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl, chartBackgroundColor As Vintasoft.Primitives.VintasoftColor, plotAreaBackgroundColor As Vintasoft.Primitives.VintasoftColor)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' create worksheet editor
Dim worksheetEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor = spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet)
Try
' create editor for focused chart
Dim chartEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor = worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing)
' create editor for chart properties
Dim chartPropertiesEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor = chartEditor.CreateChartPropertiesEditor()
' set the chart appearance
chartPropertiesEditor.SetChartAreaAppearance(New Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(chartBackgroundColor, chartPropertiesEditor.ChartProperties.ChartAreaAppearance.OutlineColor, chartPropertiesEditor.ChartProperties.ChartAreaAppearance.OutlineWidth))
' set the plot area appearance
chartPropertiesEditor.SetPlotAreaAppearance(New Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(plotAreaBackgroundColor, chartPropertiesEditor.ChartProperties.PlotAreaAppearance.OutlineColor, chartPropertiesEditor.ChartProperties.PlotAreaAppearance.OutlineWidth))
Finally
spreadsheetVisualEditor.Editor.FinishEditing()
End Try
End Sub
Вид диаграммы: Установка цвета для серии диаграммы
Вот C#/VB.NET код, который демонстрирует, как установить цвет для серии диаграммы:
/// <summary>
/// Sets the colors for the specified chart series.
/// </summary>
/// <param name="editorControl">The spreadsheet editor control.</param>
/// <param name="seriesIndex">Index of the series.</param>
public void SetColorsForChartSeriesOfXlsxChart(
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl,
int seriesIndex)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// create worksheet editor
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor worksheetEditor =
spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet);
try
{
// create editor for focused chart
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor chartEditor =
worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing);
// create editor for chart properties
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor chartPropertiesEditor =
chartEditor.CreateChartPropertiesEditor();
// create editor for chart series
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartDataSeriesEditor seriesEditor =
chartPropertiesEditor.CreateChartDataSeriesEditor(chartPropertiesEditor.ChartProperties.Series[seriesIndex]);
Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance appearance = new Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(
Vintasoft.Primitives.VintasoftColor.Black,
Vintasoft.Primitives.VintasoftColor.Red, 3);
// set appearance for chart series
seriesEditor.SetAppearanceProperties(appearance);
}
finally
{
spreadsheetVisualEditor.Editor.FinishEditing();
}
}
''' <summary>
''' Sets the colors for the specified chart series.
''' </summary>
''' <param name="editorControl">The spreadsheet editor control.</param>
''' <param name="seriesIndex">Index of the series.</param>
Public Sub SetColorsForChartSeriesOfXlsxChart(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl, seriesIndex As Integer)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' create worksheet editor
Dim worksheetEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor = spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet)
Try
' create editor for focused chart
Dim chartEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor = worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing)
' create editor for chart properties
Dim chartPropertiesEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor = chartEditor.CreateChartPropertiesEditor()
' create editor for chart series
Dim seriesEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartDataSeriesEditor = chartPropertiesEditor.CreateChartDataSeriesEditor(chartPropertiesEditor.ChartProperties.Series(seriesIndex))
Dim appearance As New Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(Vintasoft.Primitives.VintasoftColor.Black, Vintasoft.Primitives.VintasoftColor.Red, 3)
' set appearance for chart series
seriesEditor.SetAppearanceProperties(appearance)
Finally
spreadsheetVisualEditor.Editor.FinishEditing()
End Try
End Sub
Вид диаграммы: Установка цвета для точек данных диаграммы.
Вот C#/VB.NET код, который демонстрирует, как установить цвета для точек данных диаграммы:
/// <summary>
/// Sets the colors for chart data points.
/// </summary>
/// <param name="editorControl">The spreadsheet editor control.</param>
/// <param name="seriesIndex">A zero-based index of the chart series.</param>
public void SetColorsForChartDataPointsOfXlsxChart(
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl,
int seriesIndex)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// create worksheet editor
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor worksheetEditor =
spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet);
try
{
// create editor for focused chart
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor chartEditor =
worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing);
// create editor for chart properties
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor chartPropertiesEditor =
chartEditor.CreateChartPropertiesEditor();
// create editor for chart series
Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartDataSeriesEditor seriesEditor =
chartPropertiesEditor.CreateChartDataSeriesEditor(chartPropertiesEditor.ChartProperties.Series[seriesIndex]);
// create new data points
Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint[] dataPoints =
new Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint[seriesEditor.Series.DataPoints.Length];
for (int i = 0; i < dataPoints.Length; i++)
{
// get data point from chart
Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint dataPoint = seriesEditor.Series.DataPoints[i];
Vintasoft.Imaging.Office.Spreadsheet.Document.ChartMarker marker = null;
// if data point has marker
if (dataPoint.Marker != null)
{
Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance dataPointMarkerAppearance = new Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(
Vintasoft.Primitives.VintasoftColor.Red,
Vintasoft.Primitives.VintasoftColor.Blue, 3);
// create new marker for new data point
marker = new Vintasoft.Imaging.Office.Spreadsheet.Document.ChartMarker(
dataPoint.Marker.Style,
dataPoint.Marker.Size,
dataPointMarkerAppearance);
}
Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance dataPointAppearance = new Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(
Vintasoft.Primitives.VintasoftColor.Black,
Vintasoft.Primitives.VintasoftColor.Green, 3);
// change the color of new data point
dataPoints[i] = new Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint(marker, dataPointAppearance);
}
// set new data points for chart
seriesEditor.SetDataPoints(dataPoints);
}
finally
{
spreadsheetVisualEditor.Editor.FinishEditing();
}
}
''' <summary>
''' Sets the colors for chart data points.
''' </summary>
''' <param name="editorControl">The spreadsheet editor control.</param>
''' <param name="seriesIndex">A zero-based index of the chart series.</param>
Public Sub SetColorsForChartDataPointsOfXlsxChart(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl, seriesIndex As Integer)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' create worksheet editor
Dim worksheetEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.WorksheetEditor = spreadsheetVisualEditor.Editor.StartEditing(spreadsheetVisualEditor.FocusedWorksheet)
Try
' create editor for focused chart
Dim chartEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.SheetDrawingEditor = worksheetEditor.CreateDrawingEditor(spreadsheetVisualEditor.FocusedDrawing)
' create editor for chart properties
Dim chartPropertiesEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartPropertiesEditor = chartEditor.CreateChartPropertiesEditor()
' create editor for chart series
Dim seriesEditor As Vintasoft.Imaging.Office.Spreadsheet.Document.Editors.ChartDataSeriesEditor = chartPropertiesEditor.CreateChartDataSeriesEditor(chartPropertiesEditor.ChartProperties.Series(seriesIndex))
' create new data points
Dim dataPoints As Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint() = New Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint(seriesEditor.Series.DataPoints.Length - 1) {}
For i As Integer = 0 To dataPoints.Length - 1
' get data point from chart
Dim dataPoint As Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint = seriesEditor.Series.DataPoints(i)
Dim marker As Vintasoft.Imaging.Office.Spreadsheet.Document.ChartMarker = Nothing
' if data point has marker
If dataPoint.Marker IsNot Nothing Then
Dim dataPointMarkerAppearance As New Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(Vintasoft.Primitives.VintasoftColor.Red, Vintasoft.Primitives.VintasoftColor.Blue, 3)
' create new marker for new data point
marker = New Vintasoft.Imaging.Office.Spreadsheet.Document.ChartMarker(dataPoint.Marker.Style, dataPoint.Marker.Size, dataPointMarkerAppearance)
End If
Dim dataPointAppearance As New Vintasoft.Imaging.Office.Spreadsheet.Document.ShapeAppearance(Vintasoft.Primitives.VintasoftColor.Black, Vintasoft.Primitives.VintasoftColor.Green, 3)
' change the color of new data point
dataPoints(i) = New Vintasoft.Imaging.Office.Spreadsheet.Document.ChartDataPoint(marker, dataPointAppearance)
Next
' set new data points for chart
seriesEditor.SetDataPoints(dataPoints)
Finally
spreadsheetVisualEditor.Editor.FinishEditing()
End Try
End Sub
Изменение размера диаграммы рабочего листа XLSX
Если вы хотите изменить размер диаграммы рабочего листа XLSX с помощью мыши, вам следует выполнить следующие шаги:
- Нажать на диаграмму, размер которой необходимо изменить, и вы увидите 8 точек изменения размера, которые позволяют изменить размер диаграммы с помощью мыши
- Нажать на любую точку изменения размера и переместите мышь, чтобы изменить размер диаграммы
Перемещение диаграммы рабочего листа XLSX
Если вы хотите переместить (изменить положение) диаграмму рабочего листа XLSX с помощью мыши, вам следует выполнить следующие шаги:
- Навести курсор на диаграмму с помощью курсора мыши, и вы увидите курсор перемещения.
- Нажать на диаграмму и переместить мышь в новое положение диаграммы
Удаление диаграммы из листа XLSX
Вот C#/VB.NET код, который демонстрирует, как удалить диаграмму из листа XLSX:
/// <summary>
/// Removes the focused chart from worksheet.
/// </summary>
/// <param name="editorControl">The spreadsheet editor control.</param>
public void RemoveFocusedChartFromXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// remove focused drawing (picture, chart, graphics)
editorControl.VisualEditor.RemoveFocusedDrawing();
}
''' <summary>
''' Removes the focused chart from worksheet.
''' </summary>
''' <param name="editorControl">The spreadsheet editor control.</param>
Public Sub RemoveFocusedChartFromXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' remove focused drawing (picture, chart, graphics)
editorControl.VisualEditor.RemoveFocusedDrawing()
End Sub