My html file for pie chart using flotr is not fully working

446 Views Asked by At

I am just trying to draw a simple pie chart using flotr(an open source javascript for developing various charts). But the code i gave works a little part. The chart was drawn and the explode properties, horizontal and vertical lines all works fine. But the mouse tracker and the legends are not working. I think i have made some mistake in code. but i am not able to clear it. Anyone help me out please. Thanks in advance.

<html>
<head>
<script type="text/javascript" src="prototype-1.6.0.2.js"></script>
<script type="text/javascript" src="flotr.js"></script>
</head>
    <body>
        <div id="container" style="width:600px;height:300px;" ></div>

        <script type="text/javascript">
        (function basic_pie(container) {
  var
    d1 = [[0, 4]],
    d2 = [[0, 3]],
    d3 = [[0, 1.03]],
    d4 = [[0, 3.5]],
    graph;
   graph = Flotr.draw('container', [
    { data : d1, label : 'Comedy' },
    { data : d2, label : 'Action' },
    { data : d3, label : 'Romance',
      pie : {
        explode : 50
      }
    },
    { data : d4, label : 'Drama' }
  ], {
    HtmlText : false,
    grid : {
      verticalLines : false,
      horizontalLines : false
    },
    xaxis : { showLabels : false },
    yaxis : { showLabels : false },
    pie : {
      show : true, 
      explode : 6
    },
    mouse : { track : true },
    legend : {
      position : 'se',
      backgroundColor : '#D2E8FF'
    }
  });
})(document.getElementById("editor-render-0"));
</script>
</body>
</html>
2

There are 2 best solutions below

1
On BEST ANSWER

You might have an error in your legend configuration, I deleted it and the legend appeared correctly. Take a look: http://jsfiddle.net/Kpmcn/

0
On

You can check your browser's type, which browser you use? If IE, you should add

meta http-equiv="X-UA-Compatible" content="IE=edge"

on your first line in <head> segment, and add

[if IE]> script type="text/javascript" src="../lib/excanvas.js">script <![endif]

in <head> for compatibility. And you should add a line:

var container = document.getElementById(' container ');

in function basic_pie(container)'s first line to target the container element.

(caution: some of my answer string have been messed by the stackoverflow website. Sorry for that)