pub struct PieChart { /* private fields */ }Expand description
A structure representing a pie chart.
The PieChart struct allows for the creation and customization of pie charts, supporting
features such as labels, hole size for donut-style charts, slice pulling, rotation, faceting, and customizable plot titles.
It is ideal for visualizing proportions and distributions in categorical data.
§Backend Support
| Backend | Supported |
|---|---|
| Plotly | Yes |
| Plotters | – |
§Arguments
data- A reference to theDataFramecontaining the data to be plotted.labels- A string slice specifying the column name to be used for slice labels.facet- An optional string slice specifying the column name to be used for creating facets (small multiples).facet_config- An optional reference to aFacetConfigstruct for customizing facet layout and behavior.hole- An optionalf64value specifying the size of the hole in the center of the pie chart. A value of0.0creates a full pie chart, while a value closer to1.0creates a thinner ring.pull- An optionalf64value specifying the fraction by which each slice should be pulled out from the center.rotation- An optionalf64value specifying the starting angle (in degrees) of the first slice.colors- An optional vector ofRgbvalues specifying colors for consistent slice colors across facets.plot_title- An optionalTextstruct specifying the title of the plot.legend_title- An optionalTextstruct specifying the title of the legend.legend- An optional reference to aLegendstruct for customizing the legend of the plot (e.g., positioning, font, etc.).
§Example
§Basic Pie Chart with Customization
use plotlars::{PieChart, Plot, Text};
use polars::prelude::*;
let dataset = LazyCsvReader::new(PlRefPath::new("data/penguins.csv"))
.finish()
.unwrap()
.select([col("species")])
.collect()
.unwrap();
PieChart::builder()
.data(&dataset)
.labels("species")
.hole(0.4)
.pull(0.01)
.rotation(20.0)
.plot_title(
Text::from("Pie Chart")
.font("Arial")
.size(18)
.x(0.485)
)
.build()
.plot();
Implementations§
Source§impl PieChart
impl PieChart
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> PieChartBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
Source§impl PieChart
impl PieChart
pub fn try_new( data: &DataFrame, labels: &str, facet: Option<&str>, facet_config: Option<&FacetConfig>, hole: Option<f64>, pull: Option<f64>, rotation: Option<f64>, colors: Option<Vec<Rgb>>, plot_title: Option<Text>, legend_title: Option<Text>, legend: Option<&Legend>, ) -> Result<Self, PlotlarsError>
pub fn try_builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> PieChartTryBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PieChart
impl RefUnwindSafe for PieChart
impl Send for PieChart
impl Sync for PieChart
impl Unpin for PieChart
impl UnsafeUnpin for PieChart
impl UnwindSafe for PieChart
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more