pub struct QuickchartClient { /* private fields */ }Expand description
Client for interacting with the QuickChart.io API.
This client provides a builder-pattern API for configuring and generating charts.
Use new() to create a new client instance, then chain
builder methods to configure your chart before calling one of the generation methods.
§Example
use quickchart_rs::QuickchartClient;
let client = QuickchartClient::new()
.chart(r#"{"type":"bar","data":{"labels":["A","B"],"datasets":[{"data":[1,2]}]}}"#.to_string())
.width(800)
.height(400);
let url = client.get_url().unwrap();
assert!(url.starts_with("https://quickchart.io/chart"));Implementations§
Source§impl QuickchartClient
impl QuickchartClient
Sourcepub fn chart(self, chart: String) -> Self
pub fn chart(self, chart: String) -> Self
Set the Chart.js configuration as a JSON string. Both valid JSON and JavaScript object notation are supported.
pub fn width(self, width: usize) -> Self
pub fn height(self, height: usize) -> Self
pub fn device_pixel_ratio(self, dpr: f32) -> Self
Sourcepub fn background_color(self, color: String) -> Self
pub fn background_color(self, color: String) -> Self
Set the background color. Supports named colors (“transparent”, “white”), HEX (“#ffffff”), RGB (“rgb(255, 0, 0)”), and HSL (“hsl(0, 100%, 50%)”) formats.
pub fn version(self, version: String) -> Self
pub fn format(self, format: String) -> Self
Sourcepub fn get_url(&self) -> Result<String, QCError>
pub fn get_url(&self) -> Result<String, QCError>
Generate a chart URL with all configured parameters as query parameters.
§Example
use quickchart_rs::QuickchartClient;
let client = QuickchartClient::new()
.chart(r#"{"type":"bar","data":{"labels":["A","B"],"datasets":[{"data":[1,2]}]}}"#.to_string())
.width(800)
.height(400);
let url = client.get_url().unwrap();
assert!(url.starts_with("https://quickchart.io/chart"));
assert!(url.contains("w=800"));
assert!(url.contains("h=400"));Sourcepub async fn get_short_url(&self) -> Result<String, QCError>
pub async fn get_short_url(&self) -> Result<String, QCError>
Create a short URL for the chart via POST request to /chart/create.
§Example
use quickchart_rs::QuickchartClient;
let client = QuickchartClient::new()
.chart(r#"{"type":"bar","data":{"labels":["A","B"],"datasets":[{"data":[1,2]}]}}"#.to_string())
.get_short_url().await?;Sourcepub async fn post(&self) -> Result<Vec<u8>, QCError>
pub async fn post(&self) -> Result<Vec<u8>, QCError>
Download the chart image as bytes via POST request.
§Example
let client = QuickchartClient::new()
.chart(r#"{"type":"bar","data":{"labels":["A","B"],"datasets":[{"data":[1,2]}]}}"#.to_string())
.post().await?;
Trait Implementations§
Auto Trait Implementations§
impl Freeze for QuickchartClient
impl !RefUnwindSafe for QuickchartClient
impl Send for QuickchartClient
impl Sync for QuickchartClient
impl Unpin for QuickchartClient
impl !UnwindSafe for QuickchartClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more