Search code examples
f#fsharpchartfslab

how to set opacity and line type in FSharp.Charting


I know how to control color, fontsize and gridlines in FSharp.Charting. But is there way to set opacity for a line color and/or change the line type to dashed for example.

#load @"..\..\FSLAB\packages\FsLab\Fslab.fsx"

open FSharp.Charting
open System.Drawing

let rnd = System.Random()
rnd.NextDouble()
let rs = List.init 100 (fun _ -> rnd.NextDouble()-0.5)
let rs = rs |> List.scan (+) 0.

Chart.Line(rs) 
    .WithYAxis(MajorGrid = ChartTypes.Grid(Enabled=true,LineColor=Color.LightGray))
    .WithXAxis(MajorGrid = ChartTypes.Grid(Enabled=true,LineColor=Color.LightGray))

Solution

  • Something like this:

    .....
    Chart.Line(rs,Name="randomwalk") 
        .WithYAxis(MajorGrid = ChartTypes.Grid(Enabled=true,LineColor=Color.LightGray))
        .WithXAxis(MajorGrid = ChartTypes.Grid(Enabled=true,LineColor=Color.LightGray))
        .ApplyToChart(fun x -> x.Series.["randomwalk"].BorderDashStyle <- System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash)
        .ApplyToChart(fun x -> x.Series.["randomwalk"].Color <- Color.FromArgb(127, Color.Red))
    

    will set the chart randomwalk line style to ChartDashStyle.Dash and color to semi-transparent Color.Red.