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] Time for axes does not work on single day with different hours #614

Open
lobneroO opened this issue Jul 14, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@lobneroO
Copy link

Describe the bug
In the book there is an example using Utc times with just dates. This works fine.
If however you use data that is all on the same day with different times of day, all times are rendered as "00:00Z".
out

To Reproduce
MWE:

use plotters::prelude::*;
use chrono::{Utc, TimeZone};

fn main() {
  let root_area = BitMapBackend::new("out.png", (600, 400))
    .into_drawing_area();
  root_area.fill(&WHITE).unwrap();

  let start_date = Utc.with_ymd_and_hms(2019, 10, 1, 8, 0, 0).unwrap();
  let end_date = Utc.with_ymd_and_hms(2019, 10, 1, 20, 0, 0).unwrap();

    let mut ctx = ChartBuilder::on(&root_area)
        .set_label_area_size(LabelAreaPosition::Left, 40)
        .set_label_area_size(LabelAreaPosition::Bottom, 40)
        .caption("MSFT daily close price", ("sans-serif", 40))
        .build_cartesian_2d(130.0..145.0, start_date..end_date )
        .unwrap();

    ctx.configure_mesh().draw().unwrap();

    ctx.draw_series(
        LineSeries::new(
            (0..).zip(DATA.iter()).map(|(idx, price)| {
                let day = (idx / 5) * 7 + idx % 5 + 1;
                let date = Utc.with_ymd_and_hms(2019,10, 1, day, 0, 0).unwrap();
                (*price, date)
            }),
            &BLUE,
        )
    ).unwrap();

}
const DATA: [f64; 14] = [ 137.24, 136.37, 138.43, 137.41, 139.69, 140.41, 141.58, 139.55, 139.68, 139.10, 138.24, 135.67, 137.12, 138.12];

This is the example given in the book, but modified:

  • axes are swapped
  • instead of different days, everything is on the same day with different hours

Version Information
cargo.toml:
plotters = "0.3.6"

@lobneroO lobneroO added the bug Something isn't working label Jul 14, 2024
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