Baldrick
Baldrick

Reputation: 11012

flot axisLabel not working

I can't seem to get labels working on my basic Flot graph, I have stripped it down to the basics but I still can't get it to work;

<div id="graph" style="width:600px;height:300px;"></div>

<script type="text/javascript">
$(function () {
    var d1 = [[0, 13], [1, 13], [2, 13], [3, 0], [4, 17], [5, 17], [6, 13]];

    $.plot($("#graph"), [ 
        {
            data: d1,
            bars: {
                show: true
            },
            xaxis: {
                axisLabel: 'Hops'
            },
            yaxis: {
                axisLabel: 'Traceroute'
            }
       }
    ]);

});
</script>

Below is the graph I am getting. As you can see, no errors in the Chrome debug window. I did have the following simple axis label formatting settings included also but it still wouldn't work:

            axisLabelUseCanvas: true,
            axisLabelFontSizePixels: 12,
            axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
            axisLabelPadding: 5

enter image description here

Upvotes: 1

Views: 2817

Answers (2)

Ajay Gawali
Ajay Gawali

Reputation: 31

You need to include jquery.flot.axislabels plugin in your html code.

Upvotes: 0

Baldrick
Baldrick

Reputation: 11012

I have no idea how I have fixed this, but by making it more complex, I have. Perhaps a bug?

Now it works with this code:

<div id="graph" style="width:600px;height:300px;"></div>

<script type="text/javascript">
$(function () {
    var d1 = [[0, 13]];
    var d2 = [[1, 13]]; 
    var d3 = [[2, 13]];
    var d4 = [[3, 30]];
    var d5 = [[4, 17]];
    var d6 = [[5, 17]];
    var d7 = [[6, 13]];

    var data1 = [
        {
            data: d1,
            bars: {
                show: true,
                fillColor:  "#CAFFD8"
            },
            color: "#CAFFD8"
        },
        {
            data: d2,
            bars: {
                show: true,
                fillColor:  "#CAFFD8"
            },
            color: "#CAFFD8"
        },
        {
            data: d3,
            bars: {
                show: true,
                fillColor:  "#CAFFD8"
            },
            color: "#CAFFD8"
        },
        {
            data: d4,
            bars: {
                show: true,
                fillColor:  "#FF7575"
            },
            color: "#FF7575"
        },
        {
            data: d5,
            bars: {
                show: true,
                fillColor:  "#FFFF75"
            },
            color: "#FFFF75"
        },
        {
            data: d6,
            bars: {
                show: true,
                fillColor:  "#FFFF75"
            },
            color: "#FFFF75"
        },
        {
            data: d7,
            bars: {
                show: true,
                fillColor:  "#CAFFD8"
            },
            color: "#CAFFD8"
        },
    ];

    $.plot($("#graph"), data1, { 
            xaxis: {
                axisLabel: 'Hops',
                axisLabelUseCanvas: true,
                axisLabelFontSizePixels: 12,
                axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
                axisLabelPadding: 5
            },
            yaxis: {
                min: 0,
                max: 30,
                axisLabel: 'Traceroute',
                axisLabelUseCanvas: true,
                axisLabelFontSizePixels: 12,
                axisLabelFontFamily: 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
                axisLabelPadding: 5
            }
       });

});
</script>

enter image description here

Upvotes: 1

Related Questions