Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6644,6 +6644,9 @@
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-set-chart-title-properites-like-type-of-font, color, bold, size">How to set chart title properties like type of font, color, bold, size using XLsIO?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-set-invert-if-negative-option-for-a-chart">How to set invert if negative option for a chart using XLsIO?</a>
</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
title: Setting Invert If negative option in Chart properties | Syncfusion
description: This page tells how to set invert if negative option for a chart using Syncfusion XlsIO in C# (Cross-platform and Windows-specific) and VB.NET.
platform: document-processing
control: XlsIO
documentation: UG
---

# How to set invert if negative option for a chart using XlsIO?


The following code samples demonstrate how to set the "Invert if negative" option for a chart using C# (Cross-platform and Windows-specific) and VB.NET for XLSX files. For XLS (binary) file format, see the section below.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
#region Workbook Initialization
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx"));
IWorksheet worksheet = workbook.Worksheets[0];
#endregion

IChart chart = worksheet.Charts[0];

//Used to invert series color if the value is negative
(chart.Series[0] as ChartSerieImpl).InvertIfNegative = true;

#region Save
//Saving the workbook
workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx"));
#endregion
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
#region Workbook Initialization
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
#endregion

IChart chart = worksheet.Charts[0];

//Used to invert series color if the value is negative
(chart.Series[0] as ChartSerieImpl).InvertIfNegative = true;

#region Save
//Saving the workbook
workbook.SaveAs("Output.xlsx");
#endregion
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Using excelEngine As New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Xlsx
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
Dim worksheet As IWorksheet = workbook.Worksheets(0)

Dim chart As IChart = worksheet.Charts(0)

'Used to invert series color if the value is negative
DirectCast(chart.Series(0), ChartSerieImpl).InvertIfNegative = True

'Saving the workbook
workbook.SaveAs("Output.xlsx")
End Using
{% endhighlight %}
{% endtabs %}

A complete working example in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/1007137-ChartInvert/FAQ/Chart/.NET/ChartInvertIfNegative">this GitHub page</a>.

## How to set invert if negative option for a chart in XLS (binary) file format?

In case of binary file format (XLS), kindly use the following code snippet.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel97to2003;
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xls");
IWorksheet worksheet = workbook.Worksheets[0];

IChart chart = worksheet.Charts[0];

// Used to invert series color if the value is negative in XLS (binary) format
chart.Series[0].SerieFormat.Interior.SwapColorsOnNegative = true;

// Saving the workbook
workbook.SaveAs("Output.xls");
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
using (ExcelEngine excelEngine = new ExcelEngine())
{
#region Workbook Initialization
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open("InputTemplatexlsx.xls");
IWorksheet worksheet = workbook.Worksheets[0];
#endregion

IChart chart = worksheet.Charts[0];

// Used to invert series color if the value is negative in XLS (binary) format
chart.Series[0].SerieFormat.Interior.SwapColorsOnNegative = true;

#region Save
//Saving the workbook
workbook.SaveAs("Output.xls");
#endregion
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
Using excelEngine As New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Excel97to2003
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xls")
Dim worksheet As IWorksheet = workbook.Worksheets(0)

Dim chart As IChart = worksheet.Charts(0)

' Used to invert series color if the value is negative in XLS (binary) format
chart.Series(0).SerieFormat.Interior.SwapColorsOnNegative = True

' Saving the workbook
workbook.SaveAs("Output.xls")
End Using
{% endhighlight %}
{% endtabs %}