Dundas Charting Tips and Tricks > Changing chart attributes > How do I dynamically change the date format on a Dundas chart?
Oftentimes a user of a report containing a Dundas Chart wants the ability to change the date format on the labels of the x-axis. This post shows how to add a parameter to the report which gives the end user the option to choose a number of common date formats for the chart.
First, I will assume that there is already a chart added to the layout section of the report. In this example I am using the AdventureWorks database to look at unit sales of various "selected" products using a line chart. This report already has a parameter called ProductName as seen here.
This ProductName parameter utilizes a Dataset called ProductDataSet to gather the values for the user to choose from.
The first step is to add a new parameter. In my case I called the parameter xAxisDateLabelFormat. In the Available Values section I use the Label and Value so that the Label actually shows what a date "June 13" will actually look like on the x-axis label. The "Value" portion is the value that gets passed to the Dundas Chart which is the date code pertaining to that date format. The screenshot to the left shows how that parameter is set up within the SSRS Report Parameters dialog screen.
After adding this new parameter the various options that you have entered into the Label portion of the parameter list are visible when you Preview the report.
Click for larger view
You can see looking at the Report Parameter dialog box that the Default value is set up as MMM dd.
Now you have still not interfaced with the Dundas Chart and this is where you are going to dynamically change the x-Axis date format. In this case you cannot utilize the Dundas Chart Designer to pass the date format because there is not an Expression Edit next to where the date format is entered as seen here.

So the way you can pass the date format that is available in the report parameter is to do two things. The first thing you have to do is to add the report parameter to the Dundas Chart is to right-click on the chart and click on View Code. You will then see this screen.
Click for larger view
By clicking on the Code Parameters tab you will be able to add in the parameters from the report that you want the Dundas Chart to access. In the next screen shot you can see how the xAxisDateLabelFormat parameter is made accessible to the Dundas Chart.
Now the final step to make the date label format dynamic from the report parameter is to add a block of code to the PostApplyData event. In this case I will be using C# for the language.
Here is the code in the PostApplyData event:
This code utilizes the parameter that is passed to it from Reporting Services to format the date label on the x-axis. Notice that a try and a catch is utilized and a default date format will be set should there be an error.
Also, ensure that you clear out the date format in the Chart Designer as seen here:
Click for larger view
Finally when you run the report using two different date formats the x-axis labels will change dynamically.

Now when you change the x-Axis Date Label Format you will see the change in the date format in the chart.

