Search code examples
f#fsharpchart

F# Charting No Automatic Axis Range Setting?


It's not really an issue, more of a question. I am using FSharp.Charting to graph a few quick things. One thing I noticed is that the chart doesn't automatically set the axis limits for you. Say I have a list of numbers that has values between 100,000 and 200,000. The y-axis will still be based at 0. It doesn't scale to give you a good view of the data. You have to do this yourself. Or maybe there is a way, and I just haven't figured it out yet. Has anyone else ran into this issue? Any suggestions?


Solution

  • I have searched the FSharp charting code on GitHub and found nothing built in that can do automatic alignment of any axis. The best one can do is do it manually or write a function to look at all the values and then set them based on that.

    Since you did not show in your question how to set it manually I will state it here for those that don't know how it is done.

    To manually set the Y axis use WithYAxis

    let xs1 = [ for x in (double)(-100.0) .. 1.0 .. 100.0 do yield x]
    let ys1 = xs1 |> List.map (fun x -> x**4.00)
    let values1 = List.zip xs1 ys1
    Chart.Line(values1)
        .WithXAxis(Min=(-30.0), Max=(30.0), MajorTickMark = ChartTypes.TickMark(Interval=10.0, IntervalOffset = 5.0, LineWidth = 2))
        .WithYAxis(Min=(100000.0), Max=(200000.0), MajorTickMark = ChartTypes.TickMark(Interval=20000.0, IntervalOffset = 10000.0, LineWidth = 2))
    

    enter image description here