pub struct Table { /* private fields */ }Expand description
A structure representing a table plot.
The Table struct allows for the creation and customization of tables with support
for custom headers, cell formatting, column widths, and various styling options.
§Arguments
data- A reference to theDataFramecontaining the data to be displayed.columns- A vector of column names to be displayed in the table.header- An optionalHeadercomponent for custom header values and formatting.cell- An optionalCellcomponent for cell formatting.column_width- An optional column width ratio. Columns fill the available width in proportion.plot_title- An optionalTextstruct specifying the title of the plot.
§Example
use polars::prelude::*;
use plotlars::{Table, Header, Cell, Plot, Text, Rgb};
let dataset = df![
"name" => &["Alice", "Bob", "Charlie"],
"age" => &[25, 30, 35],
"city" => &["New York", "London", "Tokyo"]
]
.unwrap();
let header = Header::new()
.values(vec!["Full Name", "Years", "Location"])
.height(40.0)
.align("center")
.font("Arial")
.fill(Rgb(200, 200, 200));
let cell = Cell::new()
.height(30.0)
.align("left")
.fill(Rgb(240, 240, 240));
Table::builder()
.data(&dataset)
.columns(vec!["name", "age", "city"])
.header(&header)
.cell(&cell)
.plot_title(
Text::from("Data Table")
.font("Arial")
.size(18)
)
.build()
.plot();
Implementations§
Source§impl Table
impl Table
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4>() -> TableBuilder<'f1, 'f2, 'f3, 'f4>
pub fn builder<'f1, 'f2, 'f3, 'f4>() -> TableBuilder<'f1, 'f2, 'f3, 'f4>
Examples found in repository?
examples/table.rs (line 31)
5fn main() {
6 let dataset = df![
7 "name" => &["Alice Johnson", "Bob Smith", "Charlie Davis", "Diana Martinez", "Eva Wilson"],
8 "department" => &["Engineering", "Marketing", "Engineering", "Sales", "Marketing"],
9 "salary" => &[95000, 78000, 102000, 85000, 82000],
10 "years" => &[5, 3, 7, 4, 2]
11 ]
12 .unwrap();
13
14 let header = Header::new()
15 .values(vec![
16 "Employee Name",
17 "Department",
18 "Annual Salary ($)",
19 "Years of Service",
20 ])
21 .align("center")
22 .font("Arial Bold")
23 .fill(Rgb(70, 130, 180));
24
25 let cell = Cell::new()
26 .align("center")
27 .height(25.0)
28 .font("Arial")
29 .fill(Rgb(240, 248, 255));
30
31 Table::builder()
32 .data(&dataset)
33 .columns(vec!["name", "department", "salary", "years"])
34 .header(&header)
35 .cell(&cell)
36 .plot_title(
37 Text::from("Employee Data")
38 .font("Arial")
39 .size(20)
40 .color(Rgb(25, 25, 112)),
41 )
42 .build()
43 .plot();
44}Trait Implementations§
Source§impl PlotHelper for Table
impl PlotHelper for Table
fn get_layout(&self) -> &LayoutPlotly
fn get_traces(&self) -> &Vec<Box<dyn Trace + 'static>>
Auto Trait Implementations§
impl Freeze for Table
impl !RefUnwindSafe for Table
impl !Send for Table
impl !Sync for Table
impl Unpin for Table
impl !UnwindSafe for Table
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