[WEB] Online Players (Google Chart)

Discussion in 'Bukkit Tools' started by edocsyl, Mar 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    edocsyl

    Hi All
    I wrote a little PHP, MySql and JavaScript chart for showing the players were are online in ratio to the offline players with the google charts api.

    [​IMG]
    This plugin required the OnlineUsers (Mysql mode) or JsonAPI (methods: getPlayerLimit, getPlayerCount) plugin.

    Setting up:
    1. Download the config file and edit this.
    2. Edit your php file where you wanna show the chart.
    2.1 Import the "online_players_conf.inc.php" file.
    PHP:
    <?php
    require("online_players_conf.inc.php");
    ?>
    2.2 Paste the following code in the <head> section.
    JavaScriptCode (open)

    Code:
      <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script script type="text/javascript">
          google.load("visualization", "1", {packages:["corechart"]});
          google.setOnLoadCallback(drawChart);
          function drawChart() {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Offline');
            data.addColumn('number', 'Online');
            data.addRows([
            <?php
            echo "['Offline',$offline_count],";
            echo "['Online',$online_count]";
            ?>
            ]);
            var options = {
              title: <?php echo "'".$title."'" ?>
            };
            var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
            chart.draw(data, options);
          }
          </script>

    2.3 Paste the <div> in the right position. You also can edit it.
    HTML:
    <div id="chart_div" style="width: 500px; height: 300px;"></div>
    Example:
    Here is the example from the screenshot on the top of this thread.

    Changelog:
    Version 0.3 | Add JSON API
    Version 0.2 | Chart calculation fix
    Version 0.1 | Project Start
     
    JWhy and cheese5505 like this.
  2. Offline

    cky2250

  3. Offline

    edocsyl

  4. Offline

    DrAgonmoray

    edocsyl
    Woah, I'm glad I found this thread. Those google charts look so much easier to use than some PHP chart libraries I've used in the past.
     
  5. Offline

    edocsyl

    Update to Versio 0.3
    Now you can use the plugin OnlineUsers or the JsonApi to get the chart data.
     
Thread Status:
Not open for further replies.

Share This Page