开发者

Displaying dates in Flot from timestamps

I am trying to get my graph to display dates on the x axis instead of the timestamps. I've searched and read other posts and still can't get it to budge. Here's my code:

for($i = 0; $i < 3; $i++)
{
    $j = $i + 1;
    $query = "SELECT UNIX_TIMESTAMP(date_added)*1000, COUNT(id)
                    FROM likes
                    WHERE date_added BETWEEN
                        DATE_SUB(CURDATE(), INTERVAL $j MONTH)
                        AND DATE_SUB(CURDATE(), INTERVAL $i MONTH)";
    $result = mysql_query($query);
    echo mysql_error();
    $date = mysql_result($result, 0, 0);
    $count = mysql_result($result, 0, 1);
    $pair = array( (string)$date, (int)$count );
    array_push($data_series1, $pair);
}

    $.ajax({
    url: 'graph_likes.php?get_data=month',
    dataType: 'json',
    success: function(returned) {
        $.plot($('#container'), 
        [{
          开发者_JS百科  data: returned,
            points:
            {
                show: true
            },
            lines:
            {
                show: true
            },
            color: '#00d6e2',
            xaxis:
            {
                mode: 'time'
            }
        }]);
    }
});


If you want flot to display your timestamps nicely formatted, you can try using the timestamp format option (called timeformat):

        ...
        xaxis:
        {
            mode: 'time',
            timeformat: "%y/%m/%d"
        }
        ...

You find the option explained in this document: http://people.iola.dk/olau/flot/API.txt , look for the section called Time series data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜