Survival chart
Show how long things last when some are still going. Kaplan-Meier curves step down at each event, ticks mark censored subjects, and a table counts who is still at risk.
Remission by treatment
Share of patients still in remission, with 95% intervals. Ticks mark patients last seen in remission.
| Group | Week | At risk | Events | Censored | Survival | 95% low | 95% high |
|---|---|---|---|---|---|---|---|
| 6-MP | 6 | 21 | 3 | 1 | 86% | 62% | 95% |
| 6-MP | 7 | 17 | 1 | 0 | 81% | 56% | 92% |
| 6-MP | 9 | 16 | 0 | 1 | 81% | 56% | 92% |
| 6-MP | 10 | 15 | 1 | 1 | 75% | 50% | 89% |
| 6-MP | 11 | 13 | 0 | 1 | 75% | 50% | 89% |
| 6-MP | 13 | 12 | 1 | 0 | 69% | 43% | 85% |
| 6-MP | 16 | 11 | 1 | 0 | 63% | 37% | 80% |
| 6-MP | 17 | 10 | 0 | 1 | 63% | 37% | 80% |
| 6-MP | 19 | 9 | 0 | 1 | 63% | 37% | 80% |
| 6-MP | 20 | 8 | 0 | 1 | 63% | 37% | 80% |
| 6-MP | 22 | 7 | 1 | 0 | 54% | 27% | 75% |
| 6-MP | 23 | 6 | 1 | 0 | 45% | 19% | 68% |
| 6-MP | 25 | 5 | 0 | 1 | 45% | 19% | 68% |
| 6-MP | 32 | 4 | 0 | 2 | 45% | 19% | 68% |
| 6-MP | 34 | 2 | 0 | 1 | 45% | 19% | 68% |
| 6-MP | 35 | 1 | 0 | 1 | 45% | 19% | 68% |
| Placebo | 1 | 21 | 2 | 0 | 90% | 67% | 98% |
| Placebo | 2 | 19 | 2 | 0 | 81% | 57% | 92% |
| Placebo | 3 | 17 | 1 | 0 | 76% | 52% | 89% |
| Placebo | 4 | 16 | 2 | 0 | 67% | 43% | 83% |
| Placebo | 5 | 14 | 2 | 0 | 57% | 34% | 75% |
| Placebo | 8 | 12 | 4 | 0 | 38% | 18% | 58% |
| Placebo | 11 | 8 | 2 | 0 | 29% | 12% | 48% |
| Placebo | 12 | 6 | 2 | 0 | 19% | 6% | 38% |
| Placebo | 15 | 4 | 1 | 0 | 14% | 4% | 32% |
| Placebo | 17 | 3 | 1 | 0 | 10% | 2% | 26% |
| Placebo | 22 | 2 | 1 | 0 | 5% | 0% | 20% |
| Placebo | 23 | 1 | 1 | 0 | 0% | 0% | 0% |
Usage
use hydroxy_leptos::chart_frame::ChartFrame;
use hydroxy_leptos::survival_chart::*;
use leptos::prelude::*;
pub fn demo() -> AnyView {
// Weeks in remission from the 6-MP leukaemia trial (Freireich et al., 1963).
// `false` marks a patient still in remission when last seen (censored).
let drug = SurvivalGroup::new(
"6-MP",
[
(6.0, true),
(6.0, true),
(6.0, true),
(6.0, false),
(7.0, true),
(9.0, false),
(10.0, true),
(10.0, false),
(11.0, false),
(13.0, true),
(16.0, true),
(17.0, false),
(19.0, false),
(20.0, false),
(22.0, true),
(23.0, true),
(25.0, false),
(32.0, false),
(32.0, false),
(34.0, false),
(35.0, false),
],
);
let placebo = SurvivalGroup::new(
"Placebo",
[
1.0, 1.0, 2.0, 2.0, 3.0, 4.0, 4.0, 5.0, 5.0, 8.0, 8.0, 8.0, 8.0, 11.0, 11.0, 12.0, 12.0, 15.0, 17.0, 22.0,
23.0,
]
.map(|w| (w, true)),
);
view! {
<ChartFrame title="Remission by treatment" description="Share of patients still in remission, with 95% intervals. Ticks mark patients last seen in remission.">
<SurvivalChart
data=vec![drug, placebo]
label="Kaplan-Meier curves of weeks in remission"
time_label="Week"
show_ci=true
risk_table=true
/>
</ChartFrame>
}
.into_any()
}use dioxus::prelude::*;
use hydroxy_dioxus::chart_frame::ChartFrame;
use hydroxy_dioxus::survival_chart::{SurvivalChart, SurvivalGroup};
#[component]
pub fn SurvivalChartDemo() -> Element {
// Weeks in remission from the 6-MP leukaemia trial (Freireich et al., 1963).
// `false` marks a patient still in remission when last seen (censored).
let drug = SurvivalGroup::new(
"6-MP",
[
(6.0, true),
(6.0, true),
(6.0, true),
(6.0, false),
(7.0, true),
(9.0, false),
(10.0, true),
(10.0, false),
(11.0, false),
(13.0, true),
(16.0, true),
(17.0, false),
(19.0, false),
(20.0, false),
(22.0, true),
(23.0, true),
(25.0, false),
(32.0, false),
(32.0, false),
(34.0, false),
(35.0, false),
],
);
let placebo = SurvivalGroup::new(
"Placebo",
[
1.0, 1.0, 2.0, 2.0, 3.0, 4.0, 4.0, 5.0, 5.0, 8.0, 8.0, 8.0, 8.0, 11.0, 11.0, 12.0, 12.0, 15.0, 17.0, 22.0,
23.0,
]
.map(|w| (w, true)),
);
rsx! {
ChartFrame { title: "Remission by treatment", description: "Share of patients still in remission, with 95% intervals. Ticks mark patients last seen in remission.",
SurvivalChart {
data: vec![drug, placebo],
label: "Kaplan-Meier curves of weeks in remission",
time_label: "Week",
show_ci: true,
risk_table: true,
}
}
}
}
Anatomy
| Component | data-part | Renders |
|---|---|---|
SurvivalChart | root | figure with a screen-reader table of each group's estimate at every time; data-variant=ci with intervals |
| line | One step curve per group, drawn left to right |
| band | Greenwood 95% interval, log-log transformed (show_ci) |
| censor | Tick where a subject left the study event-free |
| crosshair | The hovered time, with a dot on each curve |
| risk-table | Number at risk at each time tick (risk_table), after the figure |
| tooltip | Each group's estimate at the hovered time |
Keyboard
| Key | Does |
|---|---|
ArrowLeft / ArrowRight | Previous or next observed time |
Home / End | First or last time |
Escape | Hide the tooltip |
Props
| Prop | Type | Notes |
|---|---|---|
data | Vec<SurvivalGroup> | Required. SurvivalGroup::new(name, [(time, event)]); event is false when censored. Up to six |
label | String | Required. What the chart shows; the accessible name |
time_label | String | What time is measured in. Default "Time" |
show_ci | bool | Shade each curve's 95% confidence interval |
risk_table | bool | Number at risk under the axis |
height | u16 | Plot height in px. Default 260 |
format | Fn(f64) -> String | Formats times |
Events
| Prop | Type | Notes |
|---|---|---|
on_hover | Callback<Option<Datum>> | The mark under the pointer or keyboard focus changes, or is left. Fires only on a change |
on_select | Callback<Datum> | Click, tap or Enter on a mark |