This is a migrated thread and some comments may be shown as answers.

Format DateTime in radChartView with multiple Series

2 Answers 211 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Sacha
Top achievements
Rank 1
Sacha asked on 06 May 2019, 02:36 PM

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 Answers, 1 is accepted

Sort by
0
Sacha
Top achievements
Rank 1
answered on 06 May 2019, 02:39 PM
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;
}
0
Accepted
Dimitar
Telerik team
answered on 07 May 2019, 10:16 AM
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.
Don
Top achievements
Rank 2
commented on 28 Aug 2024, 08:20 PM

DateTimeComponent does not exist within DateTimeCategoricalAxis

You guys need more and better examples. 
It's really hard to figure out how to use your components !

Nadya | Tech Support Engineer
Telerik team
commented on 02 Sep 2024, 09:27 AM

Hello, Don,

DateTimeComponent property does exist in the DateTimeCategoricalAxis. I have checked the provided code snippet from here and it is working correct on my side. 

Can you please confirm whether you are using RadChartView from Telerik UI for WinForms suite, or you are referring to another product. 

Please let me know if you have any other questions.

Tags
ChartView
Asked by
Sacha
Top achievements
Rank 1
Answers by
Sacha
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or