1

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))
s952163
  • 6,276
  • 4
  • 23
  • 47

1 Answers1

2

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.

Gene Belitski
  • 10,270
  • 1
  • 34
  • 54
  • This is very neat. I really need to upgrade my FSLAB. It seems this was added recently (0.90.14?) to [FSharp.Charting](https://github.com/fslaborg/FSharp.Charting/commit/b70b4a6be13cba4c9ec80de19e641ba4b5ed8fe9). Thanks! – s952163 Jul 15 '16 at 23:35
  • 2
    Right, the above snippet uses `FSharp.Charting 0.90.14`. – Gene Belitski Jul 16 '16 at 06:15