Category Y Axis, Time X Axis

2 posts, 0 answers
  1. Rob
    Rob avatar
    5 posts
    Member since:
    Dec 2011

    Posted 02 Apr 2014 Link to this post


    I'm trying to format a chart that has a status or category on the Y axis, and a time on the X axis. Please see attached image for an example of what I'm talking about. I've tried a couple different scenarios, but I'm having trouble adding CategoricalDataPoints to my LineSeries. I'm currently trying to use the RadCartesianChart, which I'm not even sure is the most appropriate. Could anyone provide some guidance on if I'm using the right chart, axes, etc...and maybe a small example of adding data to the series programatically? 

    This is what I have so far, which I know is not well written, just trying to get a POC working. The CategoricalDataPoint is expecting a double as the value, but I actually just have a category.

    RadCartesianChart chart = new RadCartesianChart();
                chart.HorizontalAxis = new DateTimeContinuousAxis();
                chart.VerticalAxis = new CategoricalAxis();
                LineSeries line = new LineSeries();
                line.Stroke = new SolidColorBrush(Colors.Orange);
                line.StrokeThickness = 2;
                SqlCeConnection con = new SqlCeConnection(connectionString); ;
                using (SqlCeCommand command = new SqlCeCommand("SELECT as contact, as status, Log.time as time FROM Log INNER JOIN Status ON Log.status_id = WHERE ( = 'Bob')", con))
                    SqlCeDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                        DateTime time = Convert.ToDateTime(reader["time"]);
                        string person = Convert.ToString(reader["contact"]);
                        string status = Convert.ToString(reader["status"]);
                        if (time.DayOfYear == DateTime.Now.DayOfYear - 1)
                            line.DataPoints.Add(new CategoricalDataPoint() { Value = time, Category = status });
  2. Pavel R. Pavlov
    Pavel R. Pavlov avatar
    1237 posts

    Posted 07 Apr 2014 Link to this post

    Hi Rob,

    You can achieve your requirement by using one DateTimeCategoricalAxis and one LinearAxis. Furthermore, you will be able to use the LabelTemplate of the LinearAxis to set a TextBlock which can be customized. You can use a converter to return the desired string, instead of the default integer values.

    For your convenience I prepared a sample project demonstrating the described approach. Please take a look at it and let me know if you need any further assistance.

    Pavel R. Pavlov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top