Format DateTime in radChartView with multiple Series

3 posts, 1 answers
  1. Sacha
    Sacha avatar
    5 posts
    Member since:
    Mar 2019

    Posted 06 May Link to this post

    Hi,

    I have a Chart with dateTimes on the X Axis. I would like to print only the hour and minutes as it isn't readable otherwise (Original.PNG).
    When I try to format it by using categoricalAxis on each series, it formats it correctly but creates an axis for each serie (Formatted.PNG).

    I haven't found a way to keep only 1 Axis but with the formatted dateTimes.
    I joined a copy of the important part of my code.

  2. Sacha
    Sacha avatar
    5 posts
    Member since:
    Mar 2019

    Posted 06 May Link to this post

    Just realized the code couldn't be attached, here it is.

    public FilesChart()
    {
        InitializeComponent();
        var db = new Context();
        var result = db.FILESPROCESSEDs.Select(m => m.TYPE).Distinct();
        List<String> listResult = result.ToList();
     
        foreach (string type in listResult)
        {
            var source = db.FILESPROCESSEDs.Where(m => m.TYPE == type);
            BarSeries test = new BarSeries
            {
                DataSource = source.ToList(),
                ValueMember = "AMOUNT",
                CategoryMember = "DATETIME",
                IsVisibleInLegend = true,
                LegendTitle = type,
                CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack
                 
                                 
            };
             
             
            /*DateTimeCategoricalAxis categoricalAxis = new DateTimeCategoricalAxis();
            categoricalAxis.DateTimeComponent = Telerik.Charting.DateTimeComponent.Hour;
            categoricalAxis.PlotMode = Telerik.Charting.AxisPlotMode.BetweenTicks;
            categoricalAxis.LabelFormat = "{0:HH:mm}";
            test.HorizontalAxis = categoricalAxis;*/
             
            radChartView1.Series.Add(test);
        }
     
        radChartView1.ShowLegend = true;
    }
  3. Answer
    Dimitar
    Admin
    Dimitar avatar
    2790 posts

    Posted 07 May Link to this post

    Hello Sacha,

    You can create one axis and assign to all series:
    public RadForm1()
    {
        InitializeComponent();
     
     
        DateTimeCategoricalAxis categoricalAxis = new DateTimeCategoricalAxis();
        categoricalAxis.DateTimeComponent = Telerik.Charting.DateTimeComponent.Hour;
        categoricalAxis.PlotMode = Telerik.Charting.AxisPlotMode.BetweenTicks;
        categoricalAxis.LabelFormat = "{0:HH:mm}";
     
        for (int i = 0; i < 10; i++)
        {
            var source = GetTable();
            BarSeries test = new BarSeries
            {
                DataSource = source,
                ValueMember = "Value",
                CategoryMember = "Time",
                IsVisibleInLegend = true,
                LegendTitle = "Item " + i,
                CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack
            };
     
            test.HorizontalAxis = categoricalAxis;
            radChartView1.Series.Add(test);
        }
        radChartView1.ShowLegend = true;
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top