Generate Chart.JS charts as image and embed them everywhere in emails, pdf reports, chat bots...!
Getting started
1. Add Chart.js Image to your project
Requirements: Rust 1.65+
Add to your Cargo.toml:
[]
= "6"
Feature Flags
async(default): Enables async methods (to_buffer(),to_file(),to_data_uri())blocking: Enables blocking/sync methods (to_buffer_blocking(),to_file_blocking(),to_data_uri_blocking())full: Enables both async and blocking
# Async only (default)
= "6"
# Blocking only
= { = "6", = false, = ["blocking"] }
# Both async and blocking
= { = "6", = ["full"] }
2. Import ChartJSImage library
use ChartJSImage;
3. Generate a chart image
use ChartJSImage;
// Async example
use ChartJSImage;
async
Table of Contents
- Enterprise support
- On-Premise support
- Constructor
- Methods
- to_url()
- to_buffer() / to_buffer_blocking()
- to_file() / to_file_blocking()
- to_data_uri() / to_data_uri_blocking()
- c(value) - Javascript/JSON definition of the chart. Use a Chart.js configuration object.
- chart(value) - Javascript/JSON definition of the chart. Use a Chart.js configuration object.
- width(value) - Width of the chart
- height(value) - Height of the chart
- backgroundColor(value) - Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
- bkg(value) - Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
- encoding(value) - Encoding of your "chart" parameter. Accepted values are url and base64.
- icac(value) - image-charts enterprise
account_id - ichm(value) - HMAC-SHA256 signature required to activate paid features
- icretina(value) - retina mode
Constructor
Create an instance with builder pattern. See usage
// Free usage - default configuration
let chart = new;
// Enterprise & Enterprise+ subscriptions
let chart = builder
.secret
.build;
// With custom timeout
let chart = builder
.secret
.timeout
.build;
// On-premise subscriptions
let chart = builder
.protocol
.host
.port
.pathname
.secret
.build;
Methods
to_url() -> String
Get the full Image-Charts API url (signed and encoded if necessary)
Usage
use ChartJSImage;
to_buffer() -> Result<Vec<u8>, ChartJSImageError> (async)
to_buffer_blocking() -> Result<Vec<u8>, ChartJSImageError> (blocking)
Do a request to Image-Charts API with current configuration and yield image bytes
Usage (async)
use ChartJSImage;
async
Usage (blocking)
use ChartJSImage;
to_file(path) -> Result<(), ChartJSImageError> (async)
to_file_blocking(path) -> Result<(), ChartJSImageError> (blocking)
Download chart and save to file
Usage (async)
use ChartJSImage;
async
to_data_uri() -> Result<String, ChartJSImageError> (async)
to_data_uri_blocking() -> Result<String, ChartJSImageError> (blocking)
Do a request to Image-Charts API with current configuration and yield a base64 encoded data URI
Usage (async)
use ChartJSImage;
async
Enterprise Support
Image-Charts Enterprise and Enterprise+ subscriptions remove the watermark and enable advanced features like custom-domain, high-resolution charts, custom fonts, multiple axis and mixed charts.
Usage
Once subscribed to a plan you will receive an ACCOUNT_ID and a SECRET_KEY.
These two parameters are mandatory to sign your request and remove the watermark.
Replace both values in the code example below:
use ChartJSImage;
On-Premise Support
Image-Charts virtual appliance can be deployed anywhere inside a customer network.
use ChartJSImage;
c( value ) -> ChartJSImage
Javascript/JSON definition of the chart. Use a Chart.js configuration object.
Usage
chart( value ) -> ChartJSImage
Javascript/JSON definition of the chart. Use a Chart.js configuration object.
Usage
width( value ) -> ChartJSImage
Width of the chart
Usage
height( value ) -> ChartJSImage
Height of the chart
Usage
backgroundColor( value ) -> ChartJSImage
Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
Usage
bkg( value ) -> ChartJSImage
Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
Usage
encoding( value ) -> ChartJSImage
Encoding of your "chart" parameter. Accepted values are url and base64.
Allowed values:
icac( value ) -> ChartJSImage
image-charts enterprise
account_id
Usage
ichm( value ) -> ChartJSImage
HMAC-SHA256 signature required to activate paid features
Usage
icretina( value ) -> ChartJSImage
retina mode
