-
Notifications
You must be signed in to change notification settings - Fork 79
Custom Graphs
Hidendra edited this page Sep 16, 2012
·
12 revisions
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.
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.
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());
}
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());
}