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

Category Y Axis, Time X Axis

1 Answer 116 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 02 Apr 2014, 05:02 PM
Hello,

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); ;
            con.Open();
            using (SqlCeCommand command = new SqlCeCommand("SELECT Log.contact as contact, Status.name as status, Log.time as time FROM Log INNER JOIN Status ON Log.status_id = Status.id WHERE (Log.contact = '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 });
                    }
                }
            }

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 07 Apr 2014, 10:33 AM
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.

Regards,
Pavel R. Pavlov
Telerik
 

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.

 
Tags
ChartView
Asked by
Rob
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or