Skip to content

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.

License

Notifications You must be signed in to change notification settings

C0dwiz/chart_server_dart

Repository files navigation

📈 Dart Chart Generator API (HTTP Bar Chart Service)

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.

✨ Features

  • 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 /chart POST endpoint for integration.
  • High Performance: Built with Dart for fast, concurrent processing suitable for microservices.
  • Dependencies: Uses the image package for efficient image manipulation.

🚀 Getting Started

Prerequisites

  1. Dart SDK: Ensure you have the Dart SDK installed.
  2. Dependencies: Make sure your pubspec.yaml is set up correctly (see below).

Installation

  1. Clone the Repository:

    git clone https://github.com/C0dwiz/chart_server_dart
    cd chart_server_dart
  2. Get Dependencies:

    dart pub get

Running the Server

Start the API server from the root directory:

dart run lib/server.dart

The console will display the URL: API start http://localhost:8080

📡 API Endpoint

The primary endpoint for chart generation is /chart, which requires a POST request with a JSON body.

POST /chart

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

Request Example (JSON Body)

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"
  }
}

Successful Response

A successful request will return:

  • Status Code: 200 OK
  • Content-Type: image/png (The response body is the raw PNG image data)

✅ Testing

To ensure the utility calculations and API routes are functioning correctly, you can run the unit tests provided in the test/ directory.

dart test

📝 Dependencies (pubspec.yaml)

This 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 framework

🤝 Contributing

Feel free to open issues or submit pull requests if you have suggestions for features, performance improvements, or bug fixes!

⚖️ License

This project is licensed under the MIT License.

See the LICENSE file for more details.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages