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>
impl<'a> ChartSeries<'a>
sourcepub fn set_categories(
&mut self,
sheet_name: &str,
first_row: WorksheetRow,
first_column: WorksheetCol,
last_row: WorksheetRow,
last_column: WorksheetCol,
) -> Result<(), XlsxError>
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"
sourcepub fn set_values(
&mut self,
sheet_name: &str,
first_row: WorksheetRow,
first_column: WorksheetCol,
last_row: WorksheetRow,
last_column: WorksheetCol,
) -> Result<(), XlsxError>
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.
sourcepub fn set_name(&mut self, name: &str) -> Result<(), XlsxError>
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");
sourcepub fn set_name_range(
&mut self,
sheet_name: &str,
row: WorksheetRow,
column: WorksheetCol,
) -> Result<(), XlsxError>
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
sourcepub fn set_line(&mut self, line: &ChartLine)
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);
sourcepub fn set_fill(&mut self, fill: &ChartFill)
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);
sourcepub fn set_invert_if_negative(&mut self)
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();
sourcepub fn set_pattern(&mut self, pattern: &ChartPattern)
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);
sourcepub fn set_marker_type(&mut self, maker_type: ChartMarkerType)
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);
sourcepub fn set_marker_size(&mut self, maker_size: u8)
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);
sourcepub fn set_marker_line(&mut self, chart_line: &ChartLine)
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);
sourcepub fn set_marker_fill(&mut self, chart_fill: &ChartFill)
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);
sourcepub fn set_smooth(&mut self, smooth: bool)
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);
sourcepub fn set_labels(&mut self)
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();