A
A
Alexander Prokopenko2022-02-10 05:36:23
C++ / C#
Alexander Prokopenko, 2022-02-10 05:36:23

How to draw a graph with time in OxyPlot of their database?

I am drawing a graph from MySQL database data, it gets data out of order for example: 2022.02.10 20:00 , and then 2022.02.10 10:00, and the graph is drawn crookedly:
62047a11eb177958696283.png

valuesX = DB.SelectDouble(ref conn, "CX");
valuesY = DB.SelectDouble(ref conn, "CY");
valuesZ = DB.SelectDouble(ref conn, "CZ");
dates = DB.Select(ref conn, "Date time");

for (int i = 0; i < dates.Count; i++)
{
    lineX.Points.Add(new DataPoint(DateTimeAxis.ToDouble(Convert.ToDateTime(dates[i])), valuesX[i]));
}            

model.Series.Add(lineX);
model.Series.Add(lineY);
model.Series.Add(lineZ);
model.Axes.Add(xAxis);
model.Axes.Add(new LinearAxis());

               
plotView1.Model = model;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananiev, 2022-02-10
@SaNNy32

Well, sort the data by time. Or in a database query, or in an array.

V
Vasily Bannikov, 2022-02-10
@vabka

It gets data out of order, for example: 2022.02.10 20:00 , and then 2022.02.10 10:00, and the graph is drawn crookedly:

SQL has the magic word ORDER BY to solve this problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question