This project is a simple, high-performance HTTP API built with Dart and the Shelf framework. It dynamically generates and serves customizable bar chart images (PNG format) based on data and optional color configurations passed in a JSON request body.
- Dynamic Bar Chart Generation: Creates PNG images from numerical data arrays.
- Fully Customizable Colors: Supports passing custom RGB values via the API for bars, background, grid lines, axes, and fonts.
- Simple REST Interface: Easy-to-use
/chartPOST endpoint for integration. - High Performance: Built with Dart for fast, concurrent processing suitable for microservices.
- Dependencies: Uses the
imagepackage for efficient image manipulation.
- Dart SDK: Ensure you have the Dart SDK installed.
- Dependencies: Make sure your
pubspec.yamlis set up correctly (see below).
-
Clone the Repository:
git clone https://github.com/C0dwiz/chart_server_dart cd chart_server_dart -
Get Dependencies:
dart pub get
Start the API server from the root directory:
dart run lib/server.dartThe console will display the URL: API start http://localhost:8080
The primary endpoint for chart generation is /chart, which requires a POST request with a JSON body.
| Key | Type | Description | Required | Example |
|---|---|---|---|---|
data |
List<num> |
The series of values to be plotted in the bar chart. | Yes | [500, 800, 1500, 1200, 700] |
colors |
Map<String, List<int>> |
An optional object to override default chart colors. | No | See below |
Send a POST request to http://localhost:8080/chart with Content-Type: application/json.
{
"data": [50, 120, 90, 150, 60, 110],
"colors": {
"bar": [255, 69, 0],
"background": [20, 20, 30],
"font": [255, 255, 255],
"grid": [60, 60, 60]
// Other available keys: "axis", "barBorder", "axisLabel"
}
}A successful request will return:
- Status Code:
200 OK - Content-Type:
image/png(The response body is the raw PNG image data)
To ensure the utility calculations and API routes are functioning correctly, you can run the unit tests provided in the test/ directory.
dart testThis project relies on the following key dependencies:
dependencies:
shelf: ^1.4.1 # Web server framework
shelf_router: ^1.1.4 # Routing middleware
image: ^4.1.3 # Image processing and drawing utilities
dev_dependencies:
test: ^1.24.0 # Unit testing frameworkFeel free to open issues or submit pull requests if you have suggestions for features, performance improvements, or bug fixes!
This project is licensed under the MIT License.
See the LICENSE file for more details.