2

我正在尝试将基本折线图的 LiveCharts 示例转换为与 Elmish.Wpf 一起使用

除了“YFormatter”之外,我对所有东西都有绑定。我应该使用哪种绑定?

type Model = {
   AllSeries: SeriesCollection
   Labels: string[]
   Formatter: ???
}

let init() = (
    AllSeries = 
       let series = new SeriesCollection()
       series.Add(new LineSeries(Title="S1", Values=new ChartVAlues<int>(seq {4; 6; 5})))
       series
    Labels = [| "Jan"; "Feb"; "Mar" |]
    Formatter = ???
}

let bindings () : Binding<Model, MessageType> list = [
    "AllSeries" |> Binding.oneWay(fun m -> m.AllSeries)
    "Labels" |> Binding.oneWay(fun m-> m.Labels)
    "YFormatter" |> ?????
]

xaml 是根据基本折线图示例

<lvc:CartesianChart Series="{Binding AllSeries}">
    <lvc:CartesianChart.AxisY>
        <lvc:Axis Title="Sales" LabelFormatter="{Binding YFormatter}"></lvc:Axis>
    </lvc:CartesianChart.AxisY>
    <lvc:CartesianChart.AxisX>
        <lvc:Axis Title="Month" Labels="{Binding Labels}"></lvc:Axis>
     </lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
4

1 回答 1

2

让它工作

该模型根本不需要“格式化程序”

所以,init无关

绑定有

"YFormatter" |> Binding.oneWay(fun m -> Func<Double,_> (fun d -> d.ToString("C")))
于 2021-04-12T07:37:43.873 回答