Search code examples
chartsf#fsharpchart

Combining charts out of list in F#


I'm trying to combine some column charts using FSharp.Charting, but I'm stuck.

For each time my recursive function do something, it creates a chart (ChartTypes.GenericChart). Then, I add this new chart to a list (ChartTypes.GenericChart list). Everything looks pretty good actually. Once the function leaves the recursive operation, it creates the Chart. The problem is that I'm not being able to combine all of the chart of the list, so what happens is that I end up with tons of column graphs, one for each list item.

I was trying with something like this:

for x in chartList do
                Chart.Combine ([
                                x
                                |> Chart.WithXAxis (LabelStyle = ChartTypes.LabelStyle(Interval=1.0))
                                |> Chart.WithYAxis (Min=0.75)              
                                ]
                                )
                |> Chart.Show

And as I said.. the output are all graphs separated and not only one combined. Anyone has an idea?

Thank you.


Solution

  • Chart.Combine expects a list of charts as input, however you are giving it individual charts one by one using the for..in..do.

    Try to first apply the styling functions to the charts and then combine them all at once.

    chartList
    |> List.map (Chart.WithXAxis (LabelStyle = ChartTypes.LabelStyle(Interval=1.0)) >> Chart.WithYAxis (Min=0.75))
    |> Chart.Combine
    |> Chart.Show