Struct ScatterView

Source
pub struct ScatterView<'a, T: Display, U: Display> { /* private fields */ }
Expand description

A View that represents data as a scatter plot.

Implementations§

Source§

impl<'a, T: Display, U: Display> ScatterView<'a, T, U>

Source

pub fn new() -> Self

Create a new empty instance of the view.

Examples found in repository?
examples/scatter_chart.rs (line 28)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90), (12, 54), (100, 40), (180, 10)];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Square)
33        .load_data(&scatter_data).unwrap();
34
35    // Generate and save the chart.
36    Chart::new()
37        .set_width(width)
38        .set_height(height)
39        .set_margins(top, right, bottom, left)
40        .add_title(String::from("Scatter Chart"))
41        .add_view(&scatter_view)
42        .add_axis_bottom(&x)
43        .add_axis_left(&y)
44        .add_left_axis_label("Custom X Axis Label")
45        .add_bottom_axis_label("Custom Y Axis Label")
46        .save("scatter-chart.svg").unwrap();
47}
More examples
Hide additional examples
examples/scatter_chart_multiple_keys.rs (line 28)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Circle)
33        .set_colors(Color::color_scheme_dark())
34        .load_data(&scatter_data).unwrap();
35
36    // Generate and save the chart.
37    Chart::new()
38        .set_width(width)
39        .set_height(height)
40        .set_margins(top, right, bottom, left)
41        .add_title(String::from("Scatter Chart"))
42        .add_view(&scatter_view)
43        .add_axis_bottom(&x)
44        .add_axis_left(&y)
45        .add_left_axis_label("Custom X Axis Label")
46        .add_bottom_axis_label("Custom Y Axis Label")
47        .save("scatter-chart-multiple-keys.svg").unwrap();
48}
examples/scatter_chart_two_datasets.rs (line 29)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
examples/composite_bar_and_scatter_chart.rs (line 37)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
10    // range (the width of the chart without the margins).
11    let x = ScaleBand::new()
12        .set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `BarDatum` trait.
25    let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];
26
27    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
28    let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
29
30    // Create VerticalBar view that is going to represent the data as vertical bars.
31    let bar_view = VerticalBarView::new()
32        .set_x_scale(&x)
33        .set_y_scale(&y)
34        .load_data(&bar_data).unwrap();
35
36    // Create Scatter view that is going to represent the data as points.
37    let scatter_view = ScatterView::new()
38        .set_x_scale(&x)
39        .set_y_scale(&y)
40        .set_label_position(PointLabelPosition::NE)
41        .set_marker_type(MarkerType::Circle)
42        .set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
43        .load_data(&scatter_data).unwrap();
44
45    // Generate and save the chart.
46    Chart::new()
47        .set_width(width)
48        .set_height(height)
49        .set_margins(top, right, bottom, left)
50        .add_title(String::from("Composite Bar + Scatter Chart"))
51        .add_view(&bar_view)                            // <-- add bar view
52        .add_view(&scatter_view)                        // <-- add scatter view
53        .add_axis_bottom(&x)
54        .add_axis_left(&y)
55        .add_left_axis_label("Units of Measurement")
56        .add_bottom_axis_label("Categories")
57        .save("composite-bar-and-scatter-chart.svg").unwrap();
58}
Source

pub fn set_x_scale(self, scale: &'a impl Scale<T>) -> Self

Set the scale for the X dimension.

Examples found in repository?
examples/scatter_chart.rs (line 29)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90), (12, 54), (100, 40), (180, 10)];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Square)
33        .load_data(&scatter_data).unwrap();
34
35    // Generate and save the chart.
36    Chart::new()
37        .set_width(width)
38        .set_height(height)
39        .set_margins(top, right, bottom, left)
40        .add_title(String::from("Scatter Chart"))
41        .add_view(&scatter_view)
42        .add_axis_bottom(&x)
43        .add_axis_left(&y)
44        .add_left_axis_label("Custom X Axis Label")
45        .add_bottom_axis_label("Custom Y Axis Label")
46        .save("scatter-chart.svg").unwrap();
47}
More examples
Hide additional examples
examples/scatter_chart_multiple_keys.rs (line 29)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Circle)
33        .set_colors(Color::color_scheme_dark())
34        .load_data(&scatter_data).unwrap();
35
36    // Generate and save the chart.
37    Chart::new()
38        .set_width(width)
39        .set_height(height)
40        .set_margins(top, right, bottom, left)
41        .add_title(String::from("Scatter Chart"))
42        .add_view(&scatter_view)
43        .add_axis_bottom(&x)
44        .add_axis_left(&y)
45        .add_left_axis_label("Custom X Axis Label")
46        .add_bottom_axis_label("Custom Y Axis Label")
47        .save("scatter-chart-multiple-keys.svg").unwrap();
48}
examples/scatter_chart_two_datasets.rs (line 30)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
examples/composite_bar_and_scatter_chart.rs (line 38)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
10    // range (the width of the chart without the margins).
11    let x = ScaleBand::new()
12        .set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `BarDatum` trait.
25    let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];
26
27    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
28    let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
29
30    // Create VerticalBar view that is going to represent the data as vertical bars.
31    let bar_view = VerticalBarView::new()
32        .set_x_scale(&x)
33        .set_y_scale(&y)
34        .load_data(&bar_data).unwrap();
35
36    // Create Scatter view that is going to represent the data as points.
37    let scatter_view = ScatterView::new()
38        .set_x_scale(&x)
39        .set_y_scale(&y)
40        .set_label_position(PointLabelPosition::NE)
41        .set_marker_type(MarkerType::Circle)
42        .set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
43        .load_data(&scatter_data).unwrap();
44
45    // Generate and save the chart.
46    Chart::new()
47        .set_width(width)
48        .set_height(height)
49        .set_margins(top, right, bottom, left)
50        .add_title(String::from("Composite Bar + Scatter Chart"))
51        .add_view(&bar_view)                            // <-- add bar view
52        .add_view(&scatter_view)                        // <-- add scatter view
53        .add_axis_bottom(&x)
54        .add_axis_left(&y)
55        .add_left_axis_label("Units of Measurement")
56        .add_bottom_axis_label("Categories")
57        .save("composite-bar-and-scatter-chart.svg").unwrap();
58}
Source

pub fn set_y_scale(self, scale: &'a impl Scale<U>) -> Self

Set the scale for the Y dimension.

Examples found in repository?
examples/scatter_chart.rs (line 30)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90), (12, 54), (100, 40), (180, 10)];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Square)
33        .load_data(&scatter_data).unwrap();
34
35    // Generate and save the chart.
36    Chart::new()
37        .set_width(width)
38        .set_height(height)
39        .set_margins(top, right, bottom, left)
40        .add_title(String::from("Scatter Chart"))
41        .add_view(&scatter_view)
42        .add_axis_bottom(&x)
43        .add_axis_left(&y)
44        .add_left_axis_label("Custom X Axis Label")
45        .add_bottom_axis_label("Custom Y Axis Label")
46        .save("scatter-chart.svg").unwrap();
47}
More examples
Hide additional examples
examples/scatter_chart_multiple_keys.rs (line 30)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Circle)
33        .set_colors(Color::color_scheme_dark())
34        .load_data(&scatter_data).unwrap();
35
36    // Generate and save the chart.
37    Chart::new()
38        .set_width(width)
39        .set_height(height)
40        .set_margins(top, right, bottom, left)
41        .add_title(String::from("Scatter Chart"))
42        .add_view(&scatter_view)
43        .add_axis_bottom(&x)
44        .add_axis_left(&y)
45        .add_left_axis_label("Custom X Axis Label")
46        .add_bottom_axis_label("Custom Y Axis Label")
47        .save("scatter-chart-multiple-keys.svg").unwrap();
48}
examples/scatter_chart_two_datasets.rs (line 31)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
examples/composite_bar_and_scatter_chart.rs (line 39)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
10    // range (the width of the chart without the margins).
11    let x = ScaleBand::new()
12        .set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `BarDatum` trait.
25    let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];
26
27    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
28    let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
29
30    // Create VerticalBar view that is going to represent the data as vertical bars.
31    let bar_view = VerticalBarView::new()
32        .set_x_scale(&x)
33        .set_y_scale(&y)
34        .load_data(&bar_data).unwrap();
35
36    // Create Scatter view that is going to represent the data as points.
37    let scatter_view = ScatterView::new()
38        .set_x_scale(&x)
39        .set_y_scale(&y)
40        .set_label_position(PointLabelPosition::NE)
41        .set_marker_type(MarkerType::Circle)
42        .set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
43        .load_data(&scatter_data).unwrap();
44
45    // Generate and save the chart.
46    Chart::new()
47        .set_width(width)
48        .set_height(height)
49        .set_margins(top, right, bottom, left)
50        .add_title(String::from("Composite Bar + Scatter Chart"))
51        .add_view(&bar_view)                            // <-- add bar view
52        .add_view(&scatter_view)                        // <-- add scatter view
53        .add_axis_bottom(&x)
54        .add_axis_left(&y)
55        .add_left_axis_label("Units of Measurement")
56        .add_bottom_axis_label("Categories")
57        .save("composite-bar-and-scatter-chart.svg").unwrap();
58}
Source

pub fn set_keys(self, keys: Vec<String>) -> Self

Set the keys in case of a stacked bar chart.

Source

pub fn set_label_position(self, label_position: PointLabelPosition) -> Self

Set the positioning of the labels.

Examples found in repository?
examples/scatter_chart.rs (line 31)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90), (12, 54), (100, 40), (180, 10)];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Square)
33        .load_data(&scatter_data).unwrap();
34
35    // Generate and save the chart.
36    Chart::new()
37        .set_width(width)
38        .set_height(height)
39        .set_margins(top, right, bottom, left)
40        .add_title(String::from("Scatter Chart"))
41        .add_view(&scatter_view)
42        .add_axis_bottom(&x)
43        .add_axis_left(&y)
44        .add_left_axis_label("Custom X Axis Label")
45        .add_bottom_axis_label("Custom Y Axis Label")
46        .save("scatter-chart.svg").unwrap();
47}
More examples
Hide additional examples
examples/scatter_chart_multiple_keys.rs (line 31)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Circle)
33        .set_colors(Color::color_scheme_dark())
34        .load_data(&scatter_data).unwrap();
35
36    // Generate and save the chart.
37    Chart::new()
38        .set_width(width)
39        .set_height(height)
40        .set_margins(top, right, bottom, left)
41        .add_title(String::from("Scatter Chart"))
42        .add_view(&scatter_view)
43        .add_axis_bottom(&x)
44        .add_axis_left(&y)
45        .add_left_axis_label("Custom X Axis Label")
46        .add_bottom_axis_label("Custom Y Axis Label")
47        .save("scatter-chart-multiple-keys.svg").unwrap();
48}
examples/scatter_chart_two_datasets.rs (line 33)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
examples/composite_bar_and_scatter_chart.rs (line 40)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
10    // range (the width of the chart without the margins).
11    let x = ScaleBand::new()
12        .set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `BarDatum` trait.
25    let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];
26
27    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
28    let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
29
30    // Create VerticalBar view that is going to represent the data as vertical bars.
31    let bar_view = VerticalBarView::new()
32        .set_x_scale(&x)
33        .set_y_scale(&y)
34        .load_data(&bar_data).unwrap();
35
36    // Create Scatter view that is going to represent the data as points.
37    let scatter_view = ScatterView::new()
38        .set_x_scale(&x)
39        .set_y_scale(&y)
40        .set_label_position(PointLabelPosition::NE)
41        .set_marker_type(MarkerType::Circle)
42        .set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
43        .load_data(&scatter_data).unwrap();
44
45    // Generate and save the chart.
46    Chart::new()
47        .set_width(width)
48        .set_height(height)
49        .set_margins(top, right, bottom, left)
50        .add_title(String::from("Composite Bar + Scatter Chart"))
51        .add_view(&bar_view)                            // <-- add bar view
52        .add_view(&scatter_view)                        // <-- add scatter view
53        .add_axis_bottom(&x)
54        .add_axis_left(&y)
55        .add_left_axis_label("Units of Measurement")
56        .add_bottom_axis_label("Categories")
57        .save("composite-bar-and-scatter-chart.svg").unwrap();
58}
Source

pub fn set_marker_type(self, marker_type: MarkerType) -> Self

Set the keys in case of a stacked bar chart.

Examples found in repository?
examples/scatter_chart.rs (line 32)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90), (12, 54), (100, 40), (180, 10)];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Square)
33        .load_data(&scatter_data).unwrap();
34
35    // Generate and save the chart.
36    Chart::new()
37        .set_width(width)
38        .set_height(height)
39        .set_margins(top, right, bottom, left)
40        .add_title(String::from("Scatter Chart"))
41        .add_view(&scatter_view)
42        .add_axis_bottom(&x)
43        .add_axis_left(&y)
44        .add_left_axis_label("Custom X Axis Label")
45        .add_bottom_axis_label("Custom Y Axis Label")
46        .save("scatter-chart.svg").unwrap();
47}
More examples
Hide additional examples
examples/scatter_chart_multiple_keys.rs (line 32)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Circle)
33        .set_colors(Color::color_scheme_dark())
34        .load_data(&scatter_data).unwrap();
35
36    // Generate and save the chart.
37    Chart::new()
38        .set_width(width)
39        .set_height(height)
40        .set_margins(top, right, bottom, left)
41        .add_title(String::from("Scatter Chart"))
42        .add_view(&scatter_view)
43        .add_axis_bottom(&x)
44        .add_axis_left(&y)
45        .add_left_axis_label("Custom X Axis Label")
46        .add_bottom_axis_label("Custom Y Axis Label")
47        .save("scatter-chart-multiple-keys.svg").unwrap();
48}
examples/scatter_chart_two_datasets.rs (line 32)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
examples/composite_bar_and_scatter_chart.rs (line 41)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
10    // range (the width of the chart without the margins).
11    let x = ScaleBand::new()
12        .set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `BarDatum` trait.
25    let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];
26
27    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
28    let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
29
30    // Create VerticalBar view that is going to represent the data as vertical bars.
31    let bar_view = VerticalBarView::new()
32        .set_x_scale(&x)
33        .set_y_scale(&y)
34        .load_data(&bar_data).unwrap();
35
36    // Create Scatter view that is going to represent the data as points.
37    let scatter_view = ScatterView::new()
38        .set_x_scale(&x)
39        .set_y_scale(&y)
40        .set_label_position(PointLabelPosition::NE)
41        .set_marker_type(MarkerType::Circle)
42        .set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
43        .load_data(&scatter_data).unwrap();
44
45    // Generate and save the chart.
46    Chart::new()
47        .set_width(width)
48        .set_height(height)
49        .set_margins(top, right, bottom, left)
50        .add_title(String::from("Composite Bar + Scatter Chart"))
51        .add_view(&bar_view)                            // <-- add bar view
52        .add_view(&scatter_view)                        // <-- add scatter view
53        .add_axis_bottom(&x)
54        .add_axis_left(&y)
55        .add_left_axis_label("Units of Measurement")
56        .add_bottom_axis_label("Categories")
57        .save("composite-bar-and-scatter-chart.svg").unwrap();
58}
Source

pub fn set_colors(self, colors: Vec<Color>) -> Self

Set the color palette of the view.

Examples found in repository?
examples/scatter_chart_multiple_keys.rs (line 33)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Circle)
33        .set_colors(Color::color_scheme_dark())
34        .load_data(&scatter_data).unwrap();
35
36    // Generate and save the chart.
37    Chart::new()
38        .set_width(width)
39        .set_height(height)
40        .set_margins(top, right, bottom, left)
41        .add_title(String::from("Scatter Chart"))
42        .add_view(&scatter_view)
43        .add_axis_bottom(&x)
44        .add_axis_left(&y)
45        .add_left_axis_label("Custom X Axis Label")
46        .add_bottom_axis_label("Custom Y Axis Label")
47        .save("scatter-chart-multiple-keys.svg").unwrap();
48}
More examples
Hide additional examples
examples/scatter_chart_two_datasets.rs (line 44)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
examples/composite_bar_and_scatter_chart.rs (line 42)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
10    // range (the width of the chart without the margins).
11    let x = ScaleBand::new()
12        .set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `BarDatum` trait.
25    let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];
26
27    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
28    let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
29
30    // Create VerticalBar view that is going to represent the data as vertical bars.
31    let bar_view = VerticalBarView::new()
32        .set_x_scale(&x)
33        .set_y_scale(&y)
34        .load_data(&bar_data).unwrap();
35
36    // Create Scatter view that is going to represent the data as points.
37    let scatter_view = ScatterView::new()
38        .set_x_scale(&x)
39        .set_y_scale(&y)
40        .set_label_position(PointLabelPosition::NE)
41        .set_marker_type(MarkerType::Circle)
42        .set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
43        .load_data(&scatter_data).unwrap();
44
45    // Generate and save the chart.
46    Chart::new()
47        .set_width(width)
48        .set_height(height)
49        .set_margins(top, right, bottom, left)
50        .add_title(String::from("Composite Bar + Scatter Chart"))
51        .add_view(&bar_view)                            // <-- add bar view
52        .add_view(&scatter_view)                        // <-- add scatter view
53        .add_axis_bottom(&x)
54        .add_axis_left(&y)
55        .add_left_axis_label("Units of Measurement")
56        .add_bottom_axis_label("Categories")
57        .save("composite-bar-and-scatter-chart.svg").unwrap();
58}
Source

pub fn set_label_visibility(self, label_visibility: bool) -> Self

Set labels visibility.

Source

pub fn set_custom_data_label(self, label: String) -> Self

Set custom label for the dataset. This will work when the dataset represents only a single type of data (i.e. there are no different “keys” by which to differentiate data), otherwise, this will have no effect.

Examples found in repository?
examples/scatter_chart_two_datasets.rs (line 34)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
Source

pub fn load_data( self, data: &Vec<impl PointDatum<T, U>>, ) -> Result<Self, String>

Load and process a dataset of BarDatum points.

Examples found in repository?
examples/scatter_chart.rs (line 33)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90), (12, 54), (100, 40), (180, 10)];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Square)
33        .load_data(&scatter_data).unwrap();
34
35    // Generate and save the chart.
36    Chart::new()
37        .set_width(width)
38        .set_height(height)
39        .set_margins(top, right, bottom, left)
40        .add_title(String::from("Scatter Chart"))
41        .add_view(&scatter_view)
42        .add_axis_bottom(&x)
43        .add_axis_left(&y)
44        .add_left_axis_label("Custom X Axis Label")
45        .add_bottom_axis_label("Custom Y Axis Label")
46        .save("scatter-chart.svg").unwrap();
47}
More examples
Hide additional examples
examples/scatter_chart_multiple_keys.rs (line 34)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
26
27    // Create Scatter view that is going to represent the data as points.
28    let scatter_view = ScatterView::new()
29        .set_x_scale(&x)
30        .set_y_scale(&y)
31        .set_label_position(PointLabelPosition::E)
32        .set_marker_type(MarkerType::Circle)
33        .set_colors(Color::color_scheme_dark())
34        .load_data(&scatter_data).unwrap();
35
36    // Generate and save the chart.
37    Chart::new()
38        .set_width(width)
39        .set_height(height)
40        .set_margins(top, right, bottom, left)
41        .add_title(String::from("Scatter Chart"))
42        .add_view(&scatter_view)
43        .add_axis_bottom(&x)
44        .add_axis_left(&y)
45        .add_left_axis_label("Custom X Axis Label")
46        .add_bottom_axis_label("Custom Y Axis Label")
47        .save("scatter-chart-multiple-keys.svg").unwrap();
48}
examples/scatter_chart_two_datasets.rs (line 35)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 80, 60);
8
9    // Create a band scale that will interpolate values in [0, 200] to values in the
10    // [0, availableWidth] range (the width of the chart without the margins).
11    let x = ScaleLinear::new()
12        .set_domain(vec![0_f32, 200_f32])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
25    let scatter_data_1 = vec![(20, 90), (12, 54), (25, 70), (33, 40)];
26    let scatter_data_2 = vec![(120, 10), (143, 34), (170, 14), (190, 13)];
27
28    // Create Scatter view that is going to represent the data as points.
29    let scatter_view_1 = ScatterView::new()
30        .set_x_scale(&x)
31        .set_y_scale(&y)
32        .set_marker_type(MarkerType::Circle)
33        .set_label_position(PointLabelPosition::N)
34        .set_custom_data_label("Apples".to_owned())
35        .load_data(&scatter_data_1).unwrap();
36
37    // Create Scatter view that is going to represent the data as points.
38    let scatter_view_2 = ScatterView::new()
39        .set_x_scale(&x)
40        .set_y_scale(&y)
41        .set_marker_type(MarkerType::Square)
42        .set_label_position(PointLabelPosition::N)
43        .set_custom_data_label("Oranges".to_owned())
44        .set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
45        .load_data(&scatter_data_2).unwrap();
46
47    // Generate and save the chart.
48    Chart::new()
49        .set_width(width)
50        .set_height(height)
51        .set_margins(top, right, bottom, left)
52        .add_title(String::from("Scatter Chart"))
53        .add_view(&scatter_view_1)
54        .add_view(&scatter_view_2)
55        .add_axis_bottom(&x)
56        .add_axis_left(&y)
57        .add_left_axis_label("Custom X Axis Label")
58        .add_bottom_axis_label("Custom Y Axis Label")
59        .add_legend_at(AxisPosition::Bottom)
60        .save("scatter-chart-two-datasets.svg").unwrap();
61}
examples/composite_bar_and_scatter_chart.rs (line 43)
3fn main() {
4    // Define chart related sizes.
5    let width = 800;
6    let height = 600;
7    let (top, right, bottom, left) = (90, 40, 50, 60);
8
9    // Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
10    // range (the width of the chart without the margins).
11    let x = ScaleBand::new()
12        .set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
13        .set_range(vec![0, width - left - right]);
14
15    // Create a linear scale that will interpolate values in [0, 100] range to corresponding
16    // values in [availableHeight, 0] range (the height of the chart without the margins).
17    // The [availableHeight, 0] range is inverted because SVGs coordinate system's origin is
18    // in top left corner, while chart's origin is in bottom left corner, hence we need to invert
19    // the range on Y axis for the chart to display as though its origin is at bottom left.
20    let y = ScaleLinear::new()
21        .set_domain(vec![0_f32, 100_f32])
22        .set_range(vec![height - top - bottom, 0]);
23
24    // You can use your own iterable as data as long as its items implement the `BarDatum` trait.
25    let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];
26
27    // You can use your own iterable as data as long as its items implement the `PointDatum` trait.
28    let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
29
30    // Create VerticalBar view that is going to represent the data as vertical bars.
31    let bar_view = VerticalBarView::new()
32        .set_x_scale(&x)
33        .set_y_scale(&y)
34        .load_data(&bar_data).unwrap();
35
36    // Create Scatter view that is going to represent the data as points.
37    let scatter_view = ScatterView::new()
38        .set_x_scale(&x)
39        .set_y_scale(&y)
40        .set_label_position(PointLabelPosition::NE)
41        .set_marker_type(MarkerType::Circle)
42        .set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
43        .load_data(&scatter_data).unwrap();
44
45    // Generate and save the chart.
46    Chart::new()
47        .set_width(width)
48        .set_height(height)
49        .set_margins(top, right, bottom, left)
50        .add_title(String::from("Composite Bar + Scatter Chart"))
51        .add_view(&bar_view)                            // <-- add bar view
52        .add_view(&scatter_view)                        // <-- add scatter view
53        .add_axis_bottom(&x)
54        .add_axis_left(&y)
55        .add_left_axis_label("Units of Measurement")
56        .add_bottom_axis_label("Categories")
57        .save("composite-bar-and-scatter-chart.svg").unwrap();
58}

Auto Trait Implementations§

§

impl<'a, T, U> Freeze for ScatterView<'a, T, U>

§

impl<'a, T, U> !RefUnwindSafe for ScatterView<'a, T, U>

§

impl<'a, T, U> !Send for ScatterView<'a, T, U>

§

impl<'a, T, U> !Sync for ScatterView<'a, T, U>

§

impl<'a, T, U> Unpin for ScatterView<'a, T, U>
where T: Unpin, U: Unpin,

§

impl<'a, T, U> !UnwindSafe for ScatterView<'a, T, U>

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>,

Source§

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>,

Source§

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.