diff --git a/charming/src/element/tooltip.rs b/charming/src/element/tooltip.rs index f1237cf..df9817e 100644 --- a/charming/src/element/tooltip.rs +++ b/charming/src/element/tooltip.rs @@ -36,6 +36,9 @@ pub struct Tooltip { #[serde(skip_serializing_if = "Option::is_none")] formatter: Option, + #[serde(skip_serializing_if = "Option::is_none")] + value_formatter: Option, + #[serde(skip_serializing_if = "Option::is_none")] position: Option, @@ -65,6 +68,7 @@ impl Tooltip { trigger_on: None, axis_pointer: None, formatter: None, + value_formatter: None, position: None, padding: None, background_color: None, @@ -93,6 +97,11 @@ impl Tooltip { self } + pub fn value_formatter>(mut self, value_formatter: F) -> Self { + self.value_formatter = Some(value_formatter.into()); + self + } + pub fn position>(mut self, position: S) -> Self { self.position = Some(position.into()); self diff --git a/gallery/src/line/distribution_of_electricity.rs b/gallery/src/line/distribution_of_electricity.rs index 45ceae3..d29f7e0 100644 --- a/gallery/src/line/distribution_of_electricity.rs +++ b/gallery/src/line/distribution_of_electricity.rs @@ -1,8 +1,8 @@ use charming::{ component::{Axis, Feature, SaveAsImage, Title, Toolbox, VisualMap, VisualMapPiece}, element::{ - AxisLabel, AxisPointer, AxisPointerType, AxisType, ItemStyle, MarkArea, MarkAreaData, - Tooltip, Trigger, + AxisLabel, AxisPointer, AxisPointerType, AxisType, Formatter, ItemStyle, MarkArea, + MarkAreaData, Tooltip, Trigger, }, series::Line, Chart, @@ -18,7 +18,8 @@ pub fn chart() -> Chart { .tooltip( Tooltip::new() .trigger(Trigger::Axis) - .axis_pointer(AxisPointer::new().type_(AxisPointerType::Cross)), + .axis_pointer(AxisPointer::new().type_(AxisPointerType::Cross)) + .value_formatter(Formatter::Function("value => value + 'W'".into())), ) .toolbox( Toolbox::new()