Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6237403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:01:21+00:00 2026-05-24T11:01:21+00:00

I need to format the labels of the time axis in a MSChart like

  • 0

I need to format the labels of the time axis in a MSChart like “CW21”, “CW22”, … I am struggling for a while and could not find any solution yet.

  1. There is a LabelStyle.Format property but this does not support (AFAIK) calendar weeks. It uses the DateTime formatting strings. Is there a way to introduce a custom formatter?

  2. In the framework I found the Calendar.GetWeekOfYear method, which would provide me with the right week number. Now the question is how to bring these together?

Is there any good strategy to setup one’s own labels on the axis in a generic manner? (without knowing in advance the min/max points of the axis)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:01:22+00:00Added an answer on May 24, 2026 at 11:01 am

    Yes, you can use the Chart.FormatNumber event e.g.:

    private void FillChart()
    {
        // register the format event
        this.chart1.FormatNumber += new EventHandler<FormatNumberEventArgs>(chart1_FormatNumber);
    
        // fill the data table with values
        DataTable dt = new DataTable();
        dt.Columns.Add("X", typeof(DateTime));
        dt.Columns.Add("Y", typeof(double));
    
        dt.Rows.Add(DateTime.Today.AddDays(1), 10);
        dt.Rows.Add(DateTime.Today.AddDays(8), 30);
        dt.Rows.Add(DateTime.Today.AddDays(15), 10);
        dt.Rows.Add(DateTime.Today.AddDays(21), 20);
        dt.Rows.Add(DateTime.Today.AddDays(25), 40);
        dt.Rows.Add(DateTime.Today.AddDays(31), 25);
    
        // bind the data table to chart
        this.chart1.Series.Clear();
    
        var series = this.chart1.Series.Add("Series 1");
        series.XValueMember = "X";
        series.YValueMembers = "Y";
    
        series.ChartType = SeriesChartType.Line;
        this.chart1.DataSource = dt;
        this.chart1.DataBind();
    
        // set a custom format to recognize the AxisX label in the event handler
        this.chart1.ChartAreas[0].AxisX.LabelStyle.Format = "CustomAxisXFormat"; 
    
    }
    
    void chart1_FormatNumber(object sender, FormatNumberEventArgs e)
    {
        if (e.ElementType == ChartElementType.AxisLabels &&
            e.Format == "CustomAxisXFormat")
        {
            if (e.ValueType == ChartValueType.DateTime)
            {
                var currentCalendar = CultureInfo.CurrentCulture.Calendar;
                e.LocalizedValue = "CW" +
                    currentCalendar.GetWeekOfYear(DateTime.FromOADate(e.Value),
                    System.Globalization.CalendarWeekRule.FirstDay,
                    CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
            }
        }
    }
    

    Here’s the result:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to change datetime format of the X Axis Tick Label between MM/dd/yyyy
I need to format text in posts using WordPress to look like a code.
this is my first question. I need to format a jqPlot chart point labels
surely this question has beed debated thousand of time, but I do not find
I need to display only time labels on xAxis. I'm using Highcharts and don't
I need format a number with NSNumberFormatter . If number is small (e.g. 0.000001
I need to format database records into a table that a web forum can
I need to format the date in an email template. The date gets included
I need to format a number so that there is a comma seperating the
My clients need a format of serial #: YYYYMMDD098 where YYYYMMDD represents today, 098

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.