Struct xlsxwriter::chart::ChartSeries

source ·
pub struct ChartSeries<'a> { /* private fields */ }
Expand description

Struct to represent an Excel chart data series. This struct is created using the chart.add_series function. It is used in functions that modify a chart series but the members of the struct aren’t modified directly.

Implementations§

source§

impl<'a> ChartSeries<'a>

source

pub fn set_categories( &mut self, sheet_name: &str, first_row: WorksheetRow, first_column: WorksheetCol, last_row: WorksheetRow, last_column: WorksheetCol, ) -> Result<(), XlsxError>

The categories and values of a chart data series are generally set using the chart_add_series function and Excel range formulas like “=Sheet1!$A$2:$A$7”.

The ChartSeries.set_categories() function is an alternative method that is easier to generate programmatically. It requires that you set the categories and values parameters in Chart.add_series to None and then set them using row and column values in ChartSeries.set_categories and ChartSeries.set_values:

let mut series = chart.add_series(None, None)?;
series.set_categories("Sheet1", 0, 0, 4, 0); // "=Sheet1!$A$1:$A$5"
series.set_values("Sheet1", 0, 1, 4, 1);     // "=Sheet1!$B$1:$B$5"
source

pub fn set_values( &mut self, sheet_name: &str, first_row: WorksheetRow, first_column: WorksheetCol, last_row: WorksheetRow, last_column: WorksheetCol, ) -> Result<(), XlsxError>

The categories and values of a chart data series are generally set using the Chart.add_series() function and Excel range formulas like “=Sheet1!$A$2:$A$7”.

The Chart.series_set_values() function is an alternative method that is easier to generate programmatically. See the documentation for ChartSeries.set_categories() above.

source

pub fn set_name(&mut self, name: &str) -> Result<(), XlsxError>

This function is used to set the name for a chart data series. The series name in Excel is displayed in the chart legend and in the formula bar. The name property is optional and if it isn’t supplied it will default to Series 1..n.

use xlsxwriter::prelude::*;
let mut series = chart.add_series(None, Some("=Sheet1!$A$2:$A$6"))?;
series.set_name("Quarterly budget data");

The name parameter can also be a formula such as =Sheet1!$A$1 to point to a cell in the workbook that contains the name:

use xlsxwriter::prelude::*;
let mut series = chart.add_series(None, Some("=Sheet1!$A$2:$A$6"))?;
series.set_name("=Sheet1!$A$1:$A$1");
source

pub fn set_name_range( &mut self, sheet_name: &str, row: WorksheetRow, column: WorksheetCol, ) -> Result<(), XlsxError>

The ChartSeries.set_name_range() function can be used to set a series name range and is an alternative to using ChartSeries.set_name() and a string formula:

let mut series = chart.add_series(None, Some("=Sheet1!$B$2:$B$6"))?;
series.set_name_range("Sheet1", 0, 1); // =Sheet1!$B$1
source

pub fn set_line(&mut self, line: &ChartLine)

Set the line/border properties of a chart series:

let mut series1 = chart.add_series(None, Some("=Sheet1!$A$2:$A$6"))?;
let mut series2 = chart.add_series(None, Some("=Sheet1!$B$2:$B$6"))?;
let mut series3 = chart.add_series(None, Some("=Sheet1!$C$2:$C$6"))?;
let mut chart_line = ChartLine::new();
chart_line.color = FormatColor::Red;
series1.set_line(&chart_line);
series2.set_line(&chart_line);
series3.set_line(&chart_line);

Result Image

source

pub fn set_fill(&mut self, fill: &ChartFill)

Set the fill properties of a chart series:

let mut chart_fill_1 = ChartFill::new();
chart_fill_1.color = FormatColor::Red;
let mut chart_fill_2 = ChartFill::new();
chart_fill_2.color = FormatColor::Yellow;
let mut chart_fill_3 = ChartFill::new();
chart_fill_3.color = FormatColor::Green;
series1.set_fill(&chart_fill_1);
series2.set_fill(&chart_fill_2);
series3.set_fill(&chart_fill_3);

Result Image

source

pub fn set_invert_if_negative(&mut self)

Invert the fill color for negative values. Usually only applicable to column and bar charts.

series1.set_invert_if_negative();
source

pub fn set_pattern(&mut self, pattern: &ChartPattern)

Set the pattern properties of a chart series:

let pattern1 = ChartPattern::new(FormatColor::Custom(0x804000), FormatColor::Custom(0xC68C53), ChartPatternType::Shingle);
series1.set_pattern(&pattern1);
let pattern2 = ChartPattern::new(FormatColor::Custom(0xB30000), FormatColor::Custom(0xFF6666), ChartPatternType::HorizontalBrick);
series2.set_pattern(&pattern2);

Result Image

source

pub fn set_marker_type(&mut self, maker_type: ChartMarkerType)

In Excel a chart marker is used to distinguish data points in a plotted series. In general only Line and Scatter and Radar chart types use markers.

series1.set_marker_type(ChartMarkerType::MarkerDiamond);

Result Image

source

pub fn set_marker_size(&mut self, maker_size: u8)

This function is used to specify the size of the series marker.

series1.set_marker_type(ChartMarkerType::MarkerDiamond);
series1.set_marker_size(10);
source

pub fn set_marker_line(&mut self, chart_line: &ChartLine)

Set the line/border properties of a chart marker.

series1.set_marker_type(ChartMarkerType::MarkerDiamond);
let mut marker_line = ChartLine::new();
marker_line.color = FormatColor::Red;
series1.set_marker_line(&marker_line);
series1.set_marker_size(10);
source

pub fn set_marker_fill(&mut self, chart_fill: &ChartFill)

Set the line/border properties of a chart marker.

series1.set_marker_type(ChartMarkerType::MarkerDiamond);
let mut marker_line = ChartLine::new();
marker_line.color = FormatColor::Red;
series1.set_marker_line(&marker_line);
let mut marker_fill = ChartFill::new();
marker_fill.color = FormatColor::Yellow;
series1.set_marker_fill(&marker_fill);
series1.set_marker_size(10);
source

pub fn set_smooth(&mut self, smooth: bool)

This function is used to set the smooth property of a line series. It is only applicable to the line and scatter chart types.

series1.set_smooth(true);

Result Image

source

pub fn set_labels(&mut self)

This function is used to turn on data labels for a chart series. Data labels indicate the values of the plotted data points.

series1.set_marker_type(ChartMarkerType::MarkerDiamond);
series1.set_labels();

Result Image

Auto Trait Implementations§

§

impl<'a> Freeze for ChartSeries<'a>

§

impl<'a> !RefUnwindSafe for ChartSeries<'a>

§

impl<'a> !Send for ChartSeries<'a>

§

impl<'a> !Sync for ChartSeries<'a>

§

impl<'a> Unpin for ChartSeries<'a>

§

impl<'a> !UnwindSafe for ChartSeries<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.