This gallery example demonstrates creating an interactive radar (spider) chart using Plotly.cpp's polar coordinate system. It compares multiple products across various performance dimensions, making it ideal for competitive analysis and multi-criteria decision making.
The radar chart enables quick visual comparison of strengths and weaknesses across different products, making patterns and trade-offs easily identifiable.
#include <cstddef>
#include <string>
#include <vector>
auto main(
int argc,
char *argv[]) ->
int {
std::vector<std::string> categories = {
"Performance", "Reliability", "Security", "Usability",
"Scalability", "Maintainability", "Documentation", "Support"};
std::vector<std::vector<double>> performanceData = {
{8.5, 9.2, 7.8, 8.9, 7.5, 8.1, 6.8, 8.7},
{7.2, 8.1, 9.5, 7.6, 8.8, 7.9, 8.5, 7.3},
{9.1, 7.8, 8.4, 9.3, 6.9, 9.2, 9.0, 8.2},
{6.8, 8.9, 7.2, 8.5, 9.1, 7.4, 7.8, 9.0}
};
std::vector<std::string> productNames = {"Product A", "Product B",
"Product C", "Product D"};
std::vector<std::string> colors = {
"rgba(255, 0, 0, 0.6)",
"rgba(0, 255, 0, 0.6)",
"rgba(0, 0, 255, 0.6)",
"rgba(255, 165, 0, 0.6)"
};
std::vector<std::string> lineColors = {"red", "green", "blue", "orange"};
std::vector<plotly::Object> traces;
for (size_t i = 0; i < performanceData.size(); i++) {
std::vector<double> values = performanceData[i];
std::vector<std::string> theta = categories;
values.push_back(values[0]);
theta.push_back(categories[0]);
{"type", "scatterpolar"},
{"r", values},
{"theta", theta},
{"fill", "toself"},
{"name", productNames[i]},
{"line", {{"color", lineColors[i]}, {"width", 3}}},
{"marker", {{"color", colors[i]}, {"size", 8}}},
{"fillcolor", colors[i]},
{"hovertemplate",
productNames[i] + "<br>%{theta}: %{r:.1f}<extra></extra>"}};
traces.push_back(trace);
}
{"title",
{{"text", "Product Performance Comparison<br>" +
std::string("<sub>Multi-dimensional Radar Chart</sub>")},
{"font", {{"size", 18}}}}},
{"polar",
{{"radialaxis",
{{"visible", true},
{"range", {0, 10}},
{"tickmode", "linear"},
{"tick0", 0},
{"dtick", 2},
{"showticklabels", true},
{"tickfont", {{"size", 12}}},
{"gridcolor", "lightgray"}}},
{"angularaxis",
{{"tickfont", {{"size", 14}}},
{"rotation", 90},
{"direction", "counterclockwise"}}}}},
{"width", 800},
{"height", 700},
{"showlegend", true},
{"legend", {{"x", 1.05}, {"y", 1.0}}},
{"annotations",
{{{"text", "Scale: 0 (Poor) to 10 (Excellent)"},
{"x", 0.5},
{"y", -0.1},
{"xref", "paper"},
{"yref", "paper"},
{"showarrow", false},
{"font", {{"size", 12}}}}}}};
if (!args.headless) {
} else {
{"width", 800},
{"height", 700},
{"filename", "polar_radar_chart"}};
}
return 0;
}
auto parseGalleryArgs(int argc, char *argv[]) -> GalleryArgs
Parse command line arguments for gallery examples.
Definition arg_parser.cpp:4
auto main() -> int
Definition gallery_animate_sin_wave.cpp:48
nlohmann::json Object
Definition plotly.hpp:26
Public Plotly C++ API header.