Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Spline Chart - Group x-axis by days/months
posted

I have created a spline chart, which displays a datetime column along the x-axis and 2 quantity columns on the y-axis (double). I am using the AxisIntervalType to control the tick mark intervals (i.e. days) and I am able to format the x-axis lables as follows: <ITEM_LABEL:dd/MM/yyyy>.

This all works fine, however, I would like to group the chart by number of days and display the number of days along the x-axis. Is this possible? Can this be achieved by changing the format of the item label to calculate days?

DataTable testData = new DataTable();

testData.Columns.Add("DateSent", typeof(DateTime));

testData.Columns.Add("Quantity1", typeof(double));

testData.Columns.Add("Quantity2", typeof(double));

Attached screenshot is what I currently have. I would ideally like to represent datetime values with number of days, and if this is possible extend this to be able to switch the view to group by weeks/months etc.

Any help would be most appreciated.

Thanks

Jon

  • 26458
    Offline posted

    You can change the date strings to pretty much anything if you use IRenderLabel interface. There should be a large number of examples on these forums and in our online help.

    First, you add this to your page_load:

    Hashtable labelHash = new Hashtable();
    labelHash.Add("CUSTOM", new LabelRenderer());
    ultraChart1.LabelHash = labelHash;
    ultraChart1.Axis.X.Labels.ItemFormatString = "<CUSTOM>";

    Then, create the following class:

    public class LabelRenderer:IRenderLabel
    {
     public string ToString(Hashtable context)
     {
      DateTime dateLabel = (DateTime)context["DATA_VALUE"];
      return dateLabel.Day.ToString();
     }
    }

    This particular code snippet replaces the date label on the x axis with the day of the month, but you can change it to anything you like.