HeatLandSeries update through ObservableCollection? #1371
Unanswered
houstonhaynes
asked this question in
Q&A
Replies: 1 comment
-
FYI - I figured it out - or I suppose I should write "I figured out one way to do it in F#" which is both more general and more specific. let seriesMap =
model.COO_PieSeries |> Seq.map (fun s -> (s :?> PieSeries<int>).Name, s) |> Map.ofSeq
chartData |> List.iter (fun (name, value) ->
match seriesMap.TryFind(name) with
| Some series ->
let pieSeries = series :?> PieSeries<int>
pieSeries.Values <- ObservableCollection<_>([| value |]) // Assign a new collection
| None ->
// Add new series
let newSeries = PieSeries<int>(Values = ObservableCollection<_>([| value |]), InnerRadius = 40.0, Name = name) :> ISeries
model.COO_PieSeries.Add(newSeries)
)
let createHeatMap () =
let selectedColorSeries = selectRandomColorSeries model.currentColorSeries
selectedColorSeries
let updateOrAddLand (series: HeatLandSeries) (name: string, value: int) =
let nameLower = name.ToLower()
let landsMap = series.Lands |> Seq.map (fun l -> (l.Name.ToLower(), l)) |> Map.ofSeq
let updatedLands =
if Map.containsKey nameLower landsMap then
landsMap
|> Map.map (fun key l ->
if key = nameLower then
HeatLand(Name = l.Name, Value = float value) :> IWeigthedMapLand
else l)
|> Map.values
else
landsMap.Add(nameLower, new HeatLand(Name = name, Value = float value) :> IWeigthedMapLand)
|> Map.values
let newHeatMap = createHeatMap()
series.HeatMap <- newHeatMap
series.Lands <- updatedLands |> Seq.toArray
updatedLands, newHeatMap
printfn $"{DateTime.Now} COO Series updated"
// Replace the COO_MapSeries in the model with the new series <<-- THIS IS THE MAGIC -->>
match model.COO_MapSeries, model.currentColorSeries with
| [| heatLandSeries |] as existingSeries, currentColorSeries ->
let updatedLandsAndHeatMaps = chartData |> List.map (fun (name, value) -> updateOrAddLand heatLandSeries (name, value))
let _, newHeatMaps = List.unzip updatedLandsAndHeatMaps
let updatedModel = { model with COO_MapSeries = existingSeries; currentColorSeries = newHeatMaps |> List.last }
// this is the second loop that calls the branch below
update (UpdateCOOGridData chartData) updatedModel
| _ ->
// Handle case where COO_MapSeries is not initialized or in an unexpected state
model And this is the result - just an interim example but illustrates the point LiveCharts_GeoMap.mp4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to use a map visual similar to CartesianCharts where an ObservableCollection is available to update as new values for various series are available. So far with the HeatLandSeries I have been able to get an initial population of values into the map but follow-ups (which are run on a subscription - fetching values out of a time series database) just cause the map "canvas" to go blank. Is there any advice on that? Am I thinking the right way about how to send in a "fresh" HeatLandSeries? Thanks in advance!
P.S. This is what I'm working on - the "doughnut" chart in the far right (country of origin) is the same data I'm expecting/hoping to see update in the HeatLandSeries (and is being updated in the same function and passed back into the same model update for the Avalonia app)
Recording.2023-11-21.165101.mp4
Beta Was this translation helpful? Give feedback.
All reactions