article

How to Add Fixed or Custom Error Bar Value for Chart inside .NET Applications

Email
Submitted on: 4/6/2016 8:09:54 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 2032
 
     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.

 
				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.
•	Setting bars values and format.
•	Write the modified presentation to a PPTX file. 
// 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
Overview: Aspose.Slides for .NET 
Aspose.Slides is a .NET component to read, write and modify a PowerPoint document without using MS PowerPoint. PowerPoint versions from 97-2007 and all three PowerPoint formats: PPT, POT, PPS are also supported. Now you can create, access, copy, clone, edit and delete slides in your presentations. Other features include PPT/PPTX printing, PPT to XPS format, saving PowerPoint slides into PDF, adding & modifying audio & video frames, using shapes like rectangles or ellipses and saving presentations in SVG format, streams or images.


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.