Aspoe.Word.dll Charts with XAxisInteval in month/Week/Years

Hi Team,

I want to implement different types of intervals on xAxis like
intervals in Months
intervals in Year
intervals in Weeks

please help on this with examples.

I am implementing in aspose.word.dll in .NET & C#.

We are using license Aspose.Total.Net.

@Amol_Hekade

To implement different types of intervals on the X-axis of a chart using Aspose.Words for .NET, you can utilize the ChartAxis.MajorUnit and ChartAxis.MinorUnit properties. These properties allow you to specify the distance between major and minor tick marks on the axis.

Here’s how you can set up the intervals for months, weeks, and years:

Example Code

using System;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Drawing.Charts;

class Program
{
    static void Main()
    {
        // Create a new document and DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);

        // Insert a chart into the document
        Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
        Chart chart = shape.Chart;

        // Clear any existing series
        chart.Series.Clear();

        // Add a series with date values for the X-axis
        chart.Series.Add("Monthly Data",
            new DateTime[]
            {
                new DateTime(2023, 1, 1),
                new DateTime(2023, 2, 1),
                new DateTime(2023, 3, 1),
                new DateTime(2023, 4, 1)
            },
            new double[] { 10, 20, 30, 40 });

        // Configure the X-axis for monthly intervals
        ChartAxis xAxis = chart.AxisX;
        xAxis.Scaling.Minimum = new AxisBound(new DateTime(2022, 12, 31).ToOADate());
        xAxis.Scaling.Maximum = new AxisBound(new DateTime(2023, 5, 1).ToOADate());
        xAxis.MajorUnit = 30; // Major unit for months (approximately 30 days)
        xAxis.MinorUnit = 7;  // Minor unit for weeks (7 days)

        // Save the document
        doc.Save("ChartWithMonthlyIntervals.docx");
    }
}

Explanation

  • MajorUnit: Set to 30 to represent approximately one month (30 days).
  • MinorUnit: Set to 7 to represent one week (7 days).
  • Scaling: The minimum and maximum values for the X-axis are set using AxisBound, which allows you to define the range of dates displayed on the axis.

You can adjust the MajorUnit and MinorUnit values based on your specific requirements for years or weeks. For example, for yearly intervals, you might set MajorUnit to 365 (days) and adjust the date range accordingly.

This approach allows you to effectively manage the display of time intervals on your chart’s X-axis using Aspose.Words for .NET.

For more detailed information, you can refer to the Aspose.Words documentation on working with charts for additional examples and options.

Hi Team, I want to Set in Month, Please help on this, not fixed 30 because Feb doesn’t have 30 days. So I want in Month.

@Amol_Hekade It looks like you simply need to set AxisTimeUnit.

Hi Alexey

Can you please help with example and code.

I not able to do that, please share some examples for this.

If you sent some sample, this will be great help to me for further Implementation.

@Amol_Hekade There is a code example in the documentation article shared above. Do you need a code example for something else? If so, please provide your code, output and expected output documents here for our reference.

This is done,

Now I want to change legend symbol and alignment to bottom left, please help on this

@Amol_Hekade Could you please create the expected output in MS Word and attach it here for our reference? We will check your document and provide you more information.