
Overview
Plotly.cpp brings the power of Plotly.js to C++. This library provides a modern C++ interface for creating interactive data visualizations with real-time updates, event handling, and export capabilities.
Plotly.cpp Demo
Key Features
- 🔗 Plotly.js API Mapping - Translation of most Plotly.js methods
- 🎨 Advanced Visualizations - Rich variety of plot types. See gallery for more examples.
Advanced Visualizations
- âš¡ Real-Time Updates - Stream data with smooth animations and live updates
Real-Time Updates
- 🔄 Bidirectional Events - Handle user interactions from C++
Bidirectional Events
Installation & Quick Start
Prerequisites
- Ubuntu Linux (tested platform)
- Chrome/Chromium browser
- C++17 or higher
Installation
Install from deb package (Recommended)
wget https://github.com/yhisaki/plotly.cpp/releases/download/v0.1.0/libplotly-cpp-0.1.0-Linux.deb
sudo apt install ./libplotly-cpp-0.1.0-Linux.deb
Install from FetchContent
Add to your CMake project using FetchContent:
include(FetchContent)
FetchContent_Declare(
plotly-cpp
GIT_REPOSITORY https://github.com/yhisaki/plotly.cpp.git
GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(plotly-cpp)
Usage
After installation, add the following to your CMakeLists.txt:
find_package(plotly-cpp REQUIRED)
target_link_libraries(your_target plotly-cpp::plotly-cpp)
Dependencies
Plotly.cpp requires the following dependencies:
- nlohmann/json - JSON serialization/deserialization. You can install it by sudo apt install nlohmann-json3-dev.
Architecture
The library uses a client-server architecture:
- C++ Backend - Your application using plotly::Figure
- WebSocket server for real-time communication
- HTTP server serving the web frontend
- JSON-RPC protocol for structured messaging
- JavaScript Frontend - Browser-based rendering engine
- Plotly.js runtime for visualization
- Event bridge for user interactions
You can find more details in Architecture Overview.
Simple Example
std::vector<double> x = {1, 2, 3, 4, 5};
std::vector<double> y = {1, 4, 2, 8, 5};
{"x", x}, {"y", y},
{"type", "scatter"},
{"mode", "lines+markers"}
};
return 0;
}
auto main() -> int
Definition gallery_animate_sin_wave.cpp:48
std::vector< Object > Array
Definition plotly.hpp:27
nlohmann::json Object
Definition plotly.hpp:26
Public Plotly C++ API header.
Hello World
Core Classes
| Class | Description |
| plotly::Figure | Main plotting interface - your primary entry point |
| plotly::Object | JSON-compatible data container (nlohmann::json alias) |
Essential Methods
For complete examples and advanced usage, visit the project repository.