Skip to content
Hidendra edited this page Apr 2, 2012 · 12 revisions

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


Here is an example using only the default graph:

try {
    Metrics metrics = new Metrics(plugin);

    // Plot the total amount of protections
    metrics.addCustomData(new Metrics.Plotter("Total Protections") {

        @Override
        public int getValue() {
            return physicalDatabase.getProtectionCount();
        }

    });

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

Multiple graphs

You can create multiple graphs very easily, for example the following: (note: the following graph implies a pie graph. At first it would show up as a line graph but can be changed to be a pie graph instead!)

try {
    Metrics metrics = new Metrics(plugin);

    // Construct a graph, which can be immediately used and considered as valid
    Graph graph = metrics.createGraph("Percentage of weapons used");

    // Diamond sword
    graph.addPlotter(new Metrics.Plotter("Diamond Sword") {

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

    });

    // Iron sword
    graph.addPlotter(new Metrics.Plotter("Iron Sword") {

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

    });

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

See also

Clone this wiki locally