How to Add Fixed or Custom Error Bar Value for Chart inside .NET Applications
This technical tip explains how .NET developers can add Error Bars for charts inside .NET applications. Aspose.Slides for .NET lets developers add the error bars for the chart series data. This article explains how to add different chart error bar lines. Aspose.Slides for .NET provides a simple API for managing error bar values. The sample code applies when using a custom value type. To specify a value, use the ErrorBarCustomValues property of a specific data point in the DataPoints collection of series, create an instance of the [{{Presentation}}] class, Add a bubble chart on desired slide, Access the first chart series and set the error bar X format, Access the first chart series and set the error bar Y format and Setting bars values and format, write the modified presentation to a PPTX file.
//your code here...// Adding Fixed Error Bar Value for Chart
//[C# Code Sample]
using (Presentation pres = new Presentation())
{
//Creating a bubble chart
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Bubble, 50, 50, 400, 300, true);
//Adding Error bars and setting its format
IErrorBarsFormat errBarX = chart.ChartData.Series[0].ErrorBarsXFormat;
IErrorBarsFormat errBarY = chart.ChartData.Series[0].ErrorBarsYFormat;
errBarX.IsVisible = true;
errBarY.IsVisible = true;
errBarX.ValueType = ErrorBarValueType.Fixed;
errBarX.Value = 0.1f;
errBarY.ValueType = ErrorBarValueType.Percentage;
errBarY.Value = 5;
errBarX.Type = ErrorBarType.Plus;
errBarY.Format.Line.Width = 2;
errBarX.HasEndCap = true;
//Saving presentation
pres.Save("ErrorBars.pptx", SaveFormat.Pptx);
}
//[VB.NET Code Sample]
'Creating empty presentation
Using pres As Presentation = New Presentation()
'Creating a bubble chart
Dim chart As IChart = pres.Slides(0).Shapes.AddChart(ChartType.Bubble, 50, 50, 400, 300, True)
'Adding Error bars and setting its format
Dim errBarX As IErrorBarsFormat = chart.ChartData.Series(0).ErrorBarsXFormat
Dim errBarY As IErrorBarsFormat = chart.ChartData.Series(0).ErrorBarsYFormat
errBarX.IsVisible = True
errBarY.IsVisible = True
errBarX.ValueType = ErrorBarValueType.Fixed
errBarX.Value = 0.1F
errBarY.ValueType = ErrorBarValueType.Percentage
errBarY.Value = 5
errBarX.Type = ErrorBarType.Plus
errBarY.Format.Line.Width = 2
errBarX.HasEndCap = True
'Saving presentation
pres.Save("ErrorBars.pptx", SaveFormat.Pptx)
End Using
// Adding Custom Error Bar Value for Chart
//[C# Code Sample]
//Aspose.Slides for .NET provides a simple API for managing custom error bar values.
//Creating empty presentation
using (Presentation pres = new Presentation())
{
//Creating a bubble chart
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Bubble, 50, 50, 400, 300, true);
//Adding custom Error bars and setting its format
IChartSeries series = chart.ChartData.Series[0];
IErrorBarsFormat errBarX = series.ErrorBarsXFormat;
IErrorBarsFormat errBarY = series.ErrorBarsYFormat;
errBarX.IsVisible = true;
errBarY.IsVisible = true;
errBarX.ValueType = ErrorBarValueType.Custom;
errBarY.ValueType = ErrorBarValueType.Custom;
//Accessing chart series data point and setting error bars values for individual point
IChartDataPointCollection points = series.DataPoints;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXPlusValues = DataSourceType.DoubleLiterals;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXMinusValues = DataSourceType.DoubleLiterals;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYPlusValues = DataSourceType.DoubleLiterals;
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYMinusValues = DataSourceType.DoubleLiterals;
//Setting error bars for chart series points
for (int i = 0; i < points.Count; i++)
{
points[i].ErrorBarsCustomValues.XMinus.AsLiteralDouble = i + 1;
points[i].ErrorBarsCustomValues.XPlus.AsLiteralDouble = i + 1;
points[i].ErrorBarsCustomValues.YMinus.AsLiteralDouble = i + 1;
points[i].ErrorBarsCustomValues.YPlus.AsLiteralDouble = i + 1;
}
//Saving presentation
pres.Save("ErrorBarsCustomValues", SaveFormat.Pptx);
}
//[VB.NET Code Sample]
'Creating empty presentation
Using pres As Presentation = New Presentation()
'Creating a bubble chart
Dim chart As IChart = pres.Slides(0).Shapes.AddChart(ChartType.Bubble, 50, 50, 400, 300, True)
Dim series As IChartSeries = chart.ChartData.Series(0)
'Adding custom Error bars and setting its format
Dim errBarX As IErrorBarsFormat = series.ErrorBarsXFormat
Dim errBarY As IErrorBarsFormat = series.ErrorBarsYFormat
errBarX.IsVisible = True
errBarY.IsVisible = True
errBarX.ValueType = ErrorBarValueType.Custom
errBarY.ValueType = ErrorBarValueType.Custom
'Accessing chart series data point and setting error bars values for individual point
Dim points As IChartDataPointCollection = series.DataPoints
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXPlusValues = DataSourceType.DoubleLiterals
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForXMinusValues = DataSourceType.DoubleLiterals
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYPlusValues = DataSourceType.DoubleLiterals
points.DataSourceTypeForErrorBarsCustomValues.DataSourceTypeForYMinusValues = DataSourceType.DoubleLiterals
'Setting error bars for chart series points
For i As Integer = 0 To points.Count
points(i).ErrorBarsCustomValues.XMinus.AsLiteralDouble = i + 1
points(i).ErrorBarsCustomValues.XPlus.AsLiteralDouble = i + 1
points(i).ErrorBarsCustomValues.YMinus.AsLiteralDouble = i + 1
points(i).ErrorBarsCustomValues.YPlus.AsLiteralDouble = i + 1
Next
'Saving presentation
pres.Save("ErrorBarsCustomValues", SaveFormat.Pptx)
End Using
Url: http://www.aspose.com/.net/powerpoint-component.aspx
Language: C# | User: Sheraz Khan | Created: Apr 6, 2016 | Tags: Adding Fixed Error Bar Value for Chart Add Custom Error Bar Value for Chart managing custom error bar values Add a bubble chart on desired slide .NET PowerPoint API PowerPoint .NET Component