Custom graphs - Hidendra/Plugin-Metrics GitHub Wiki

Custom Graphs are one of the more powerful features of Metrics which allows you to submit your own, custom data which is automatically tracked and graphed. This allows you to create different kinds of graphs such as Line, Area, Column, and Pie graphs without changing any of your code. You can have more than one graph.

NOTE: As of September 16, 2012 new graphs are hidden by default. If you want to show a graph that is hidden you will need to log into the admin portal and change it in there.


You can create multiple graphs very easily. The following example is an example of something that would work well as a pie graph. At first it would show up as a line graph however this can be changed in the admin panel.

If only one server submitted data it would show 4/21=19% for Diamond Sword and 17/21=81% for Iron Sword. It simply sums up all the data for all servers. The numeric literals will usually be your own variable unless you use 1 (e.g. to denote a feature is enabled, for example).

try {
    Metrics metrics = new Metrics(plugin);

    Graph weaponsUsedGraph = metrics.createGraph("Percentage of weapons used");

    weaponsUsedGraph.addPlotter(new Metrics.Plotter("Diamond Sword") {

            @Override
            public int getValue() {
                    return 4; // Number of players who used a diamond sword
            }

    });

    weaponsUsedGraph.addPlotter(new Metrics.Plotter("Iron Sword") {

            @Override
            public int getValue() {
                    return 17;
            }

    });

    metrics.start();
} catch (IOException e) {
    log(e.getMessage());
}

See also

⚠️ **GitHub.com Fallback** ⚠️