Bounds Of Axis In A Chart
This tutorial explains how to set the bounds of an axis in a chart using Aspose.Words for .NET. By inserting a chart, adding series data, and configuring the axis scaling, you can define the minimum and maximum values for the axis.
Prerequisites
To follow this tutorial, you need to have the following:
- Aspose.Words for .NET library installed.
- Basic knowledge of C# and Words Processing with Word documents.
Step 1: Set up the Document Directory
Start by setting up the path to your document directory. Replace "YOUR DOCUMENT DIRECTORY"
with the actual path to the directory where you want to save the document.
string dataDir = "YOUR DOCUMENT DIRECTORY";
Step 2: Create a New Document and DocumentBuilder
Create a new instance of the Document
class and a DocumentBuilder
object to work with the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Step 3: Insert and Configure a Chart
Insert a chart into the document using the InsertChart
method of the DocumentBuilder
object. Set the desired chart type and dimensions.
Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
Chart chart = shape.Chart;
Step 4: Add Series Data
Clear any existing series in the chart and add new series data. In this example, we add a series with labels “Item 1” to “Item 5” and corresponding values.
chart.Series.Clear();
chart.Series.Add("Aspose Series 1",
new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" },
new double[] { 1.2, 0.3, 2.1, 2.9, 4.2 });
Step 5: Set the Bounds of the Axis
Configure the scaling of the Y-axis by setting the minimum and maximum values using the Scaling.Minimum
and Scaling.Maximum
properties of the axis.
chart.AxisY.Scaling.Minimum = new AxisBound(0);
chart.AxisY.Scaling.Maximum = new AxisBound(6);
Step 6: Save the Document
Save the document to the specified directory using the Save
method. Provide the desired filename with the appropriate file extension. In this example, we save the document as “WorkingWithCharts.BoundsOfAxis.docx”.
doc.Save(dataDir + "WorkingWithCharts.BoundsOfAxis.docx");
Example source code for Bounds Of Axis using Aspose.Words for .NET
// Path to your document directory
string dataDir = "YOUR DOCUMENT DIRECTORY";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
Chart chart = shape.Chart;
chart.Series.Clear();
chart.Series.Add("Aspose Series 1",
new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" },
new double[] { 1.2, 0.3, 2.1, 2.9, 4.2 });
chart.AxisY.Scaling.Minimum = new AxisBound(0);
chart.AxisY.Scaling.Maximum = new AxisBound(6);
doc.Save(dataDir + "WorkingWithCharts.BoundsOfAxis.docx");
That’s it! You have successfully set the bounds of an axis in a chart using Aspose.Words for .NET.
Conclusion
In this tutorial, you have learned how to set the bounds of an axis in a chart using Aspose.Words for .NET. By following the step-by-step guide, you can insert and configure a chart, add series data, and define the minimum and maximum values for the axis scaling. Aspose.Words for .NET provides a powerful and flexible API for Words Processing with Word documents, allowing you to create dynamic and visually appealing charts with ease.
FAQs
Q1. What is Aspose.Words for .NET?
Aspose.Words for .NET is a library that allows developers to work with Word documents programmatically. It provides a wide range of features and functionalities for creating, manipulating, and saving Word documents.
Q2. How can I install Aspose.Words for .NET?
To install Aspose.Words for .NET, you can use NuGet package manager in Visual Studio. Simply search for “Aspose.Words” in the NuGet package manager and install it into your project.
Q3. Can I use Aspose.Words for .NET with other programming languages?
No, Aspose.Words for .NET is specifically designed for .NET applications. It works with programming languages such as C# and VB.NET.
Q4. Are there any other prerequisites for using Aspose.Words for .NET?
Besides installing the Aspose.Words for .NET library, you should have a basic knowledge of C# programming and Words Processing with Word documents. Familiarity with the .NET framework will also be helpful.