Time Series Charts with QFlot

In the previous tutorial, you saw how to create a basic bar chart with QFlot. This tutorial builds upon the knowledge from the last one - so if you want to build a time series graph, check it out first, still!

In this example, we'll create a graph of players' scores over time. Take a look at what we got below.. Pretty cute chart, right? It's really easy to create with QFlot. First, let's see how each line is constructed. Each line is really just a QFlotSeries; unlike the bar chart example where each series had only one datapoint, here we have multiple datapoints for each.

So we go ahead and create QFlotSeries objects, setting visual parameters on each. Note how one of the lines has tickmarks (little circles where the value points are) and the other one doesn't. Same with the line fill (the fill underneath the series line that covers the area under the curve). These are just settings like Points and LinesFill on the QFlotSeries object.

If you look at the code for this example, you'll also notice that the time series can be specified through a couple different data source formats. For example, $gonzaloData array specifies the x-axis values through formatted dates; $melissaData does so through timestamps.

Just like on the bar chart example, we can set the DataSet property on the QFlotSeries to pass in an entire formatted dataset as the list of values. If you don't have one created, it might save you time to use the AddDataPoint($time, $y) method instead.

Last couple tricks: you can easily add a linear regression trendline to you chart by calling MakeTrend on the QFlot object and passing in the series you want regressed. You can also create a QDataGrid out of the values in your chart easily - which might be useful to show a values table right under it, like in the example below. To do so, use the CreateDataGrid on the QFlot object.

Players


Gonzalo (X) Gonzalo (Y) Melissa (X) Melissa (Y) Bob (X) Bob (Y) Melissa Trend (X) Melissa Trend (Y)
Jan 07 2008 8 Jan 07 2008 3 Jan 07 2008 1 Jan 07 2008 5.0920221169035
Jan 08 2008 1 Jan 08 2008 8 Jan 08 2008 0 Jan 08 2008 4.9451026856241
Jan 09 2008 4 Jan 09 2008 1 Jan 09 2008 3 Jan 09 2008 4.7981832543444
Jan 10 2008 5 Jan 10 2008 6 Jan 10 2008 4 Jan 10 2008 4.6512638230647
Jan 11 2008 5 Jan 11 2008 6 Jan 11 2008 3 Jan 11 2008 4.5043443917853
Jan 14 2008 7 Jan 14 2008 1 Jan 14 2008 4 Jan 14 2008 4.0635860979462
Jan 15 2008 1 Jan 15 2008 7 Jan 15 2008 7 Jan 15 2008 3.9166666666667
Jan 16 2008 4 Jan 16 2008 5 Jan 16 2008 8 Jan 16 2008 3.7697472353871
Jan 21 2008 5 Jan 21 2008 2 Jan 21 2008 9 Jan 21 2008 3.0351500789889
Jan 22 2008 2 Jan 22 2008 4 Jan 22 2008 8 Jan 22 2008 2.8882306477094
Jan 23 2008 7 Jan 23 2008 2 Jan 23 2008 9 Jan 23 2008 2.7413112164297
Jan 24 2008 2 Jan 24 2008 2 Jan 24 2008 11 Jan 24 2008 2.59439178515