pub struct Chart { /* private fields */ }Expand description
Implementations§
Source§impl Chart
impl Chart
Sourcepub fn new() -> Chart
pub fn new() -> Chart
A chart with one auto-ranged pane, the dark theme, UTC labels and 100 000-sample series.
Examples found in repository?
10fn main() {
11 let mut chart = Chart::new();
12 let candles = chart.add_candles(Chart::MAIN, "XYZ").unwrap();
13 let volume = chart.add_pane(Pane { weight: 1.0, y_range: YRange::AutoFromZero, title: Some("Volume".into()) });
14 chart.add_volume(volume, candles).unwrap();
15 let mut price = 100.0f64;
16 for i in 0..90 {
17 let open = price;
18 price += ((i as f64) * 0.7).sin() * 1.5;
19 let (hi, lo) = (open.max(price) + 0.6, open.min(price) - 0.6);
20 chart.push_candle(candles, Candle::new(i * MINUTE, open, hi, lo, price, 20.0 + (i % 7) as f64 * 5.0)).unwrap();
21 }
22 chart.show_latest(60 * MINUTE);
23
24 let area = Rect::new(0, 0, 80, 24);
25 let mut buf = Buffer::empty(area);
26 ChartWidget::new(&chart).render(area, &mut buf);
27 for y in 0..area.height {
28 let line: String = (0..area.width).map(|x| buf[(x, y)].symbol().to_string()).collect();
29 println!("{}", line.trim_end());
30 }
31}Sourcepub fn set_time_zone(&mut self, tz: TimeZone)
pub fn set_time_zone(&mut self, tz: TimeZone)
Changes the time zone used for time labels.
Sourcepub fn set_default_capacity(&mut self, capacity: usize)
pub fn set_default_capacity(&mut self, capacity: usize)
The capacity given to series added from now on.
Sourcepub fn add_pane(&mut self, pane: Pane) -> PaneId
pub fn add_pane(&mut self, pane: Pane) -> PaneId
Adds a pane below the existing ones, with relative height weight (the main pane has 3).
Examples found in repository?
10fn main() {
11 let mut chart = Chart::new();
12 let candles = chart.add_candles(Chart::MAIN, "XYZ").unwrap();
13 let volume = chart.add_pane(Pane { weight: 1.0, y_range: YRange::AutoFromZero, title: Some("Volume".into()) });
14 chart.add_volume(volume, candles).unwrap();
15 let mut price = 100.0f64;
16 for i in 0..90 {
17 let open = price;
18 price += ((i as f64) * 0.7).sin() * 1.5;
19 let (hi, lo) = (open.max(price) + 0.6, open.min(price) - 0.6);
20 chart.push_candle(candles, Candle::new(i * MINUTE, open, hi, lo, price, 20.0 + (i % 7) as f64 * 5.0)).unwrap();
21 }
22 chart.show_latest(60 * MINUTE);
23
24 let area = Rect::new(0, 0, 80, 24);
25 let mut buf = Buffer::empty(area);
26 ChartWidget::new(&chart).render(area, &mut buf);
27 for y in 0..area.height {
28 let line: String = (0..area.width).map(|x| buf[(x, y)].symbol().to_string()).collect();
29 println!("{}", line.trim_end());
30 }
31}Sourcepub fn pane_count(&self) -> usize
pub fn pane_count(&self) -> usize
The number of panes.
Sourcepub fn add_series(
&mut self,
pane: PaneId,
name: impl Into<String>,
mark: Mark,
style: SeriesStyle,
) -> Result<SeriesId, ChartError>
pub fn add_series( &mut self, pane: PaneId, name: impl Into<String>, mark: Mark, style: SeriesStyle, ) -> Result<SeriesId, ChartError>
Adds a series. Volume series take their data from candles via
add_volume instead.
Sourcepub fn add_line(
&mut self,
pane: PaneId,
name: impl Into<String>,
color: Rgba,
) -> Result<SeriesId, ChartError>
pub fn add_line( &mut self, pane: PaneId, name: impl Into<String>, color: Rgba, ) -> Result<SeriesId, ChartError>
Adds a line series in color to pane.
Sourcepub fn add_candles(
&mut self,
pane: PaneId,
name: impl Into<String>,
) -> Result<SeriesId, ChartError>
pub fn add_candles( &mut self, pane: PaneId, name: impl Into<String>, ) -> Result<SeriesId, ChartError>
Adds a candlestick series to pane, with a last-value tag.
Examples found in repository?
10fn main() {
11 let mut chart = Chart::new();
12 let candles = chart.add_candles(Chart::MAIN, "XYZ").unwrap();
13 let volume = chart.add_pane(Pane { weight: 1.0, y_range: YRange::AutoFromZero, title: Some("Volume".into()) });
14 chart.add_volume(volume, candles).unwrap();
15 let mut price = 100.0f64;
16 for i in 0..90 {
17 let open = price;
18 price += ((i as f64) * 0.7).sin() * 1.5;
19 let (hi, lo) = (open.max(price) + 0.6, open.min(price) - 0.6);
20 chart.push_candle(candles, Candle::new(i * MINUTE, open, hi, lo, price, 20.0 + (i % 7) as f64 * 5.0)).unwrap();
21 }
22 chart.show_latest(60 * MINUTE);
23
24 let area = Rect::new(0, 0, 80, 24);
25 let mut buf = Buffer::empty(area);
26 ChartWidget::new(&chart).render(area, &mut buf);
27 for y in 0..area.height {
28 let line: String = (0..area.width).map(|x| buf[(x, y)].symbol().to_string()).collect();
29 println!("{}", line.trim_end());
30 }
31}Sourcepub fn add_volume(
&mut self,
pane: PaneId,
candles: SeriesId,
) -> Result<SeriesId, ChartError>
pub fn add_volume( &mut self, pane: PaneId, candles: SeriesId, ) -> Result<SeriesId, ChartError>
Adds volume bars for the candle series candles to pane (usually a pane of its own
with YRange::AutoFromZero). The volume shares the candles’ data.
Examples found in repository?
10fn main() {
11 let mut chart = Chart::new();
12 let candles = chart.add_candles(Chart::MAIN, "XYZ").unwrap();
13 let volume = chart.add_pane(Pane { weight: 1.0, y_range: YRange::AutoFromZero, title: Some("Volume".into()) });
14 chart.add_volume(volume, candles).unwrap();
15 let mut price = 100.0f64;
16 for i in 0..90 {
17 let open = price;
18 price += ((i as f64) * 0.7).sin() * 1.5;
19 let (hi, lo) = (open.max(price) + 0.6, open.min(price) - 0.6);
20 chart.push_candle(candles, Candle::new(i * MINUTE, open, hi, lo, price, 20.0 + (i % 7) as f64 * 5.0)).unwrap();
21 }
22 chart.show_latest(60 * MINUTE);
23
24 let area = Rect::new(0, 0, 80, 24);
25 let mut buf = Buffer::empty(area);
26 ChartWidget::new(&chart).render(area, &mut buf);
27 for y in 0..area.height {
28 let line: String = (0..area.width).map(|x| buf[(x, y)].symbol().to_string()).collect();
29 println!("{}", line.trim_end());
30 }
31}Sourcepub fn series_ids(&self) -> impl Iterator<Item = SeriesId> + use<>
pub fn series_ids(&self) -> impl Iterator<Item = SeriesId> + use<>
Every series id, in the order they were added.
Sourcepub fn series_count(&self) -> usize
pub fn series_count(&self) -> usize
The number of series.
Sourcepub fn style(&self, id: SeriesId) -> Option<&SeriesStyle>
pub fn style(&self, id: SeriesId) -> Option<&SeriesStyle>
A series’ style.
Sourcepub fn set_style(
&mut self,
id: SeriesId,
style: SeriesStyle,
) -> Result<(), ChartError>
pub fn set_style( &mut self, id: SeriesId, style: SeriesStyle, ) -> Result<(), ChartError>
Changes a series’ style.
Sourcepub fn set_mark(&mut self, id: SeriesId, mark: Mark) -> Result<(), ChartError>
pub fn set_mark(&mut self, id: SeriesId, mark: Mark) -> Result<(), ChartError>
Changes the mark of a series between kinds that hold the same data (line, area and bars; or candles and OHLC).
Sourcepub fn set_visible(
&mut self,
id: SeriesId,
visible: bool,
) -> Result<(), ChartError>
pub fn set_visible( &mut self, id: SeriesId, visible: bool, ) -> Result<(), ChartError>
Shows or hides a series.
Sourcepub fn candles(&self, id: SeriesId) -> Option<&Series<Candle>>
pub fn candles(&self, id: SeriesId) -> Option<&Series<Candle>>
A candle series’ data (also for a volume series, which shares it).
Sourcepub fn points_mut(
&mut self,
id: SeriesId,
) -> Result<&mut Series<Point>, ChartError>
pub fn points_mut( &mut self, id: SeriesId, ) -> Result<&mut Series<Point>, ChartError>
Edits a point series directly (bulk loads, capacity changes).
Sourcepub fn candles_mut(
&mut self,
id: SeriesId,
) -> Result<&mut Series<Candle>, ChartError>
pub fn candles_mut( &mut self, id: SeriesId, ) -> Result<&mut Series<Candle>, ChartError>
Edits a candle series directly.
Sourcepub fn push_point(
&mut self,
id: SeriesId,
point: Point,
) -> Result<Change, ChartError>
pub fn push_point( &mut self, id: SeriesId, point: Point, ) -> Result<Change, ChartError>
Appends a point (or replaces the newest one with the same time).
Sourcepub fn push_candle(
&mut self,
id: SeriesId,
candle: Candle,
) -> Result<Change, ChartError>
pub fn push_candle( &mut self, id: SeriesId, candle: Candle, ) -> Result<Change, ChartError>
Appends a candle (or replaces the newest one with the same time).
Examples found in repository?
10fn main() {
11 let mut chart = Chart::new();
12 let candles = chart.add_candles(Chart::MAIN, "XYZ").unwrap();
13 let volume = chart.add_pane(Pane { weight: 1.0, y_range: YRange::AutoFromZero, title: Some("Volume".into()) });
14 chart.add_volume(volume, candles).unwrap();
15 let mut price = 100.0f64;
16 for i in 0..90 {
17 let open = price;
18 price += ((i as f64) * 0.7).sin() * 1.5;
19 let (hi, lo) = (open.max(price) + 0.6, open.min(price) - 0.6);
20 chart.push_candle(candles, Candle::new(i * MINUTE, open, hi, lo, price, 20.0 + (i % 7) as f64 * 5.0)).unwrap();
21 }
22 chart.show_latest(60 * MINUTE);
23
24 let area = Rect::new(0, 0, 80, 24);
25 let mut buf = Buffer::empty(area);
26 ChartWidget::new(&chart).render(area, &mut buf);
27 for y in 0..area.height {
28 let line: String = (0..area.width).map(|x| buf[(x, y)].symbol().to_string()).collect();
29 println!("{}", line.trim_end());
30 }
31}Sourcepub fn apply_trade(
&mut self,
id: SeriesId,
time: Timestamp,
price: f64,
size: f64,
interval_ms: i64,
) -> Result<Change, ChartError>
pub fn apply_trade( &mut self, id: SeriesId, time: Timestamp, price: f64, size: f64, interval_ms: i64, ) -> Result<Change, ChartError>
Folds a trade into a candle series with interval_ms bars.
Sourcepub fn set_points(
&mut self,
id: SeriesId,
points: Vec<Point>,
) -> Result<(), ChartError>
pub fn set_points( &mut self, id: SeriesId, points: Vec<Point>, ) -> Result<(), ChartError>
Replaces a point series’ contents (history loads); sorts by time.
Sourcepub fn set_candles(
&mut self,
id: SeriesId,
candles: Vec<Candle>,
) -> Result<(), ChartError>
pub fn set_candles( &mut self, id: SeriesId, candles: Vec<Candle>, ) -> Result<(), ChartError>
Replaces a candle series’ contents (history loads); sorts by time.
Sourcepub fn latest_time(&self) -> Option<Timestamp>
pub fn latest_time(&self) -> Option<Timestamp>
The newest sample time across all series.
Sourcepub fn earliest_time(&self) -> Option<Timestamp>
pub fn earliest_time(&self) -> Option<Timestamp>
The oldest sample time across all series.
Sourcepub fn viewport_mut(&mut self) -> &mut Viewport
pub fn viewport_mut(&mut self) -> &mut Viewport
Edits the viewport directly.
Sourcepub fn show_latest(&mut self, span: i64)
pub fn show_latest(&mut self, span: i64)
Shows the last span milliseconds of data and follows new data.
Examples found in repository?
10fn main() {
11 let mut chart = Chart::new();
12 let candles = chart.add_candles(Chart::MAIN, "XYZ").unwrap();
13 let volume = chart.add_pane(Pane { weight: 1.0, y_range: YRange::AutoFromZero, title: Some("Volume".into()) });
14 chart.add_volume(volume, candles).unwrap();
15 let mut price = 100.0f64;
16 for i in 0..90 {
17 let open = price;
18 price += ((i as f64) * 0.7).sin() * 1.5;
19 let (hi, lo) = (open.max(price) + 0.6, open.min(price) - 0.6);
20 chart.push_candle(candles, Candle::new(i * MINUTE, open, hi, lo, price, 20.0 + (i % 7) as f64 * 5.0)).unwrap();
21 }
22 chart.show_latest(60 * MINUTE);
23
24 let area = Rect::new(0, 0, 80, 24);
25 let mut buf = Buffer::empty(area);
26 ChartWidget::new(&chart).render(area, &mut buf);
27 for y in 0..area.height {
28 let line: String = (0..area.width).map(|x| buf[(x, y)].symbol().to_string()).collect();
29 println!("{}", line.trim_end());
30 }
31}Sourcepub fn pan_pixels(&mut self, dx: f64, width: f64)
pub fn pan_pixels(&mut self, dx: f64, width: f64)
Pans for a drag of dx pixels across a plot width pixels wide (dragging right shows
earlier data). Panning back to the newest data resumes following.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Chart
impl Freeze for Chart
impl Move for Chart
impl RefUnwindSafe for Chart
impl Send for Chart
impl Sync for Chart
impl Unpin for Chart
impl UnsafeUnpin for Chart
impl UnwindSafe for Chart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more