Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] x_labels(n) add more entries than n. #526

Open
SoapyDev opened this issue Dec 14, 2023 · 0 comments
Open

[BUG] x_labels(n) add more entries than n. #526

SoapyDev opened this issue Dec 14, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@SoapyDev
Copy link

SoapyDev commented Dec 14, 2023

So I could not find a mention of this, excuse me if it already exist.

Description

Doing a
- LineSeries with the SVGBackend, using NaiveDate as labels on the x-axis.

Expected :

  • Limiting the x_labels to 12 should actually limit it to 12.
  • Limiting the x_labels to 12 should not create extra labels

Results :

  • The graph contains 13 dates.
  • The graph created a date that is not existent in the data.
  • See the repetition of 2023-03

exemple

To reproduce

Code

from & to are NaiveDate made from String going from the first date in the data, to the last.

       let root_area =
            SVGBackend::new(&path, (width, height)).into_drawing_area();
       root_area.fill(&WHITE)?;

    let mut chart = ChartBuilder::on(&root_area)
        .caption(title, ("inter", 30.0).into_font())
        .margin(10)
        .set_label_area_size(LabelAreaPosition::Left, 8.percent())
        .set_label_area_size(LabelAreaPosition::Bottom, 8.percent())
        .set_label_area_size(LabelAreaPosition::Right, 8.percent())
        .build_cartesian_2d(from..to, 0..max)?;

    chart
        .configure_mesh()
        .x_labels(12)
        .y_labels(10)
        .x_label_formatter(&|d| d.format(format).to_string())
        .x_desc("Date")
        .y_desc("Beneficiaires")
        .x_max_light_lines(max_lines)
        .y_max_light_lines(1)
        .draw()?;
    
    for (i, values) in data.iter().enumerate() {
        let color = *colors.get(i % colors.len()).unwrap_or(&BLACK);
        let label = labels.get(i % labels.len());
        let label = label.unwrap().as_str();
        chart
            .draw_series(LineSeries::new(
                values
                    .iter()
                    .map(|(date, x)| (NaiveDate::from_str(date).unwrap(), *x)),
                &color,
            ))?
            .label(label)
            .legend(move |(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], color));
     }

Data

As you can see, I am feeding 5 lines of data, all of them use the same dates.
Only one date exist per month.

[
    [("2023-01-04", 48), ("2023-02-01", 47), ("2023-03-01", 20), ("2023-04-05", 47), ("2023-05-03", 38), 
     ("2023-06-07", 43), ("2023-07-05", 47), ("2023-08-02", 33), ("2023-09-06", 44), ("2023-10-04", 44), 
     ("2023-11-01", 35), ("2023-12-06", 48)],

    [("2023-01-04", 40), ("2023-02-01", 31), ("2023-03-01", 30), ("2023-04-05", 36), ("2023-05-03", 28), 
     ("2023-06-07", 20), ("2023-07-05", 49), ("2023-08-02", 43), ("2023-09-06", 44), ("2023-10-04", 44), 
     ("2023-11-01", 47), ("2023-12-06", 37)],

    [("2023-01-04", 35), ("2023-02-01", 29), ("2023-03-01", 42), ("2023-04-05", 39), ("2023-05-03", 24), 
     ("2023-06-07", 26), ("2023-07-05", 30), ("2023-08-02", 37), ("2023-09-06", 44), ("2023-10-04", 28), 
     ("2023-11-01", 34), ("2023-12-06", 35)],

    [("2023-01-04", 23), ("2023-02-01", 42), ("2023-03-01", 42), ("2023-04-05", 45), ("2023-05-03", 40), 
     ("2023-06-07", 40), ("2023-07-05", 28), ("2023-08-02", 23), ("2023-09-06", 28), ("2023-10-04", 43), 
     ("2023-11-01", 25), ("2023-12-06", 45)],

    [("2023-01-04", 36), ("2023-02-01", 39), ("2023-03-01", 39), ("2023-04-05", 33), ("2023-05-03", 45), 
     ("2023-06-07", 35), ("2023-07-05", 22), ("2023-08-02", 39), ("2023-09-06", 49), ("2023-10-04", 22), 
     ("2023-11-01", 41), ("2023-12-06", 49)]
]

Version information

  • Ubuntu 23.04
  • Rust 1.74 default
  • Plotters 0.3.5 features : datetime
@SoapyDev SoapyDev added the bug Something isn't working label Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant