how to set opacity and line type in FSharp.Charting

183 Views Asked by At

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))
1

There are 1 best solutions below

2
Gene Belitski On BEST ANSWER

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.

Related Questions in F#