Basics
Adding a custom chart consists of two steps: provide the data in your plugin code and register the chart on the website.
- Navigate to your plugin page and click Edit.
- Add a new chart and assign the chart ID you use in code.
bStats ships a handful of chart types you can wire into your Metrics instance.
Adding a custom chart consists of two steps: provide the data in your plugin code and register the chart on the website.
Great for categorical data such as configuration options Simple pies track one value per server. Advanced pies let you collect multiple values per server.
metrics.addCustomChart(new SimplePie("used_language", () -> {
return config.getString("language", "English");
}));
// If you use the copy & paste Metrics classes, use `Metrics.SimplePie` insteadmetrics.addCustomChart(new Metrics.AdvancedPie("player_gamemodes", () -> {
Map<String, Integer> gamemodeMap = new HashMap<>();
for (Player player : Bukkit.getOnlinePlayers()) {
String gamemode = player.getGameMode().name();
gamemodeMap.put(gamemode, gamemodeMap.getOrDefault(gamemode, 0) + 1);
}
return gamemodeMap;
}));
// If you use the copy & paste Metrics classes, use `Metrics.AdvancedPie` insteadIdeal when you want to group categories and drill into details.
metrics.addCustomChart(new DrilldownPie("java_version", () -> {
// Format: Map<Category, Map<Subcategory, Count>>
Map<String, Map<String, Integer>> data = new HashMap<>();
String javaVersion = System.getProperty("java.version");
Map<String, Integer> subCategory = new HashMap<>();
subCategory.put(javaVersion, 1);
if (javaVersion.startsWith("1.7")) {
data.put("Java 7", subCategory);
} else if (javaVersion.startsWith("1.8")) {
data.put("Java 8", subCategory);
} else if (javaVersion.startsWith("1.9")) {
data.put("Java 9", subCategory);
} else {
data.put("Other", subCategory);
}
return data;
}));
// If you use the copy & paste Metrics classes, use `Metrics.DrilldownPie` insteadTrack trends over time. Single line charts are perfect for players, servers, or any value that has one sample per interval. Multi line charts let you compare metrics side by side.
metrics.addCustomChart(new SingleLineChart("players", () -> {
// There is already a player count chart by
// default. This is just an example.
return Bukkit.getOnlinePlayers().size();
}));
// If you use the copy & paste Metrics classes, use `Metrics.SingleLineChart` insteadmetrics.addCustomChart(new MultiLineChart("players_and_servers", () -> {
Map<String, Integer> valueMap = new HashMap<>();
valueMap.put("servers", 1);
valueMap.put("players", Bukkit.getOnlinePlayers().size());
return valueMap;
}));
// If you use the copy & paste Metrics classes, use `Metrics.MultiLineChart` instead(Note: Multi line charts are still in development)
Surface rankings or option adoption. Simple bar charts display a single value per category. Advanced bar charts support multiple bars per category.
metrics.addCustomChart(new SimpleBarChart("features", () -> {
// Format: Map<Category, Value>
Map<String, Integer> map = new HashMap<>();
map.put("Feature A", 1);
return map;
}));
// If you use the copy & paste Metrics classes, use `Metrics.SimpleBarChart`insteadmetrics.addCustomChart(new AdvancedBarChart("features", () -> {
// Format: Map<Category, [<Bar 1 Value>, <Bar 2 Value>, ...]>
Map<String, int[]> map = new HashMap<>();
map.put("Feature A", new int[]{0, 1});
map.put("Feature B", new int[]{1, 0});
return map;
}));
// If you use the copy & paste Metrics classes, use `Metrics.AdvancedBarChart` instead