FSharp.Charting


FSharp.Charting: Further Samples

This is a collection of additional samples for FSharp.Charting.

The samples are not yet individually documented but may be useful to try.

  1: 
  2: 
  3: 
  4: 
  5: 
  6: 
  7: 
  8: 
  9: 
 10: 
 11: 
 12: 
 13: 
 14: 
 15: 
 16: 
 17: 
 18: 
 19: 
 20: 
 21: 
 22: 
 23: 
 24: 
 25: 
 26: 
 27: 
 28: 
 29: 
 30: 
 31: 
 32: 
 33: 
 34: 
 35: 
 36: 
 37: 
 38: 
 39: 
 40: 
 41: 
 42: 
 43: 
 44: 
 45: 
 46: 
 47: 
 48: 
 49: 
 50: 
 51: 
 52: 
 53: 
 54: 
 55: 
 56: 
 57: 
 58: 
 59: 
 60: 
 61: 
 62: 
 63: 
 64: 
 65: 
 66: 
 67: 
 68: 
 69: 
 70: 
 71: 
 72: 
 73: 
 74: 
 75: 
 76: 
 77: 
 78: 
 79: 
 80: 
 81: 
 82: 
 83: 
 84: 
 85: 
 86: 
 87: 
 88: 
 89: 
 90: 
 91: 
 92: 
 93: 
 94: 
 95: 
 96: 
 97: 
 98: 
 99: 
100: 
101: 
102: 
103: 
104: 
105: 
106: 
107: 
108: 
109: 
110: 
111: 
112: 
113: 
114: 
115: 
116: 
117: 
118: 
119: 
120: 
121: 
122: 
123: 
124: 
125: 
126: 
127: 
128: 
129: 
130: 
131: 
132: 
133: 
134: 
135: 
136: 
137: 
138: 
139: 
140: 
141: 
142: 
143: 
144: 
145: 
146: 
147: 
148: 
149: 
150: 
151: 
152: 
153: 
154: 
155: 
156: 
157: 
158: 
159: 
160: 
161: 
162: 
163: 
164: 
165: 
166: 
167: 
168: 
169: 
170: 
171: 
172: 
173: 
174: 
175: 
176: 
177: 
178: 
179: 
180: 
181: 
182: 
183: 
184: 
185: 
186: 
187: 
188: 
189: 
190: 
191: 
192: 
193: 
// On Mac OSX use FSharp.Charting.Gtk.fsx
#I "packages/FSharp.Charting"
#load "FSharp.Charting.fsx"

open FSharp.Charting
open System
open System.Drawing

let data = [ for x in 0 .. 99 -> (x,x*x) ]
let data2 = [ for x in 0 .. 99 -> (x,sin(float x / 10.0)) ]
let data3 = [ for x in 0 .. 99 -> (x,cos(float x / 10.0)) ]
let timeSeriesData = 
  [ for x in 0 .. 99 -> (DateTime.Now.AddDays (float x),sin(float x / 10.0)) ]

let rnd = new System.Random()
let rand() = rnd.NextDouble()
let pointsWithSizes = 
  [ for i in 0 .. 30 -> (rand() * 10.0, rand() * 10.0, rand() / 100.0) ]
let pointsWithSizes2 = 
  [ for i in 0 .. 10 -> (rand() * 10.0, rand() * 10.0, rand() / 100.0) ]

let timeHighLowOpenClose = 
    [ for i in 0 .. 10 ->
         let mid = rand() * 10.0 
         (DateTime.Now.AddDays (float i), mid + 0.5, mid - 0.5, mid + 0.25, mid - 0.25) ]
let timedPointsWithSizes = 
    [ for i in 0 .. 30 -> (DateTime.Now.AddDays(rand() * 10.0), rand() * 10.0, rand() / 100.0) ]

Chart.Line(data).WithXAxis(MajorGrid=ChartTypes.Grid(Enabled=false))

Chart.Line [ DateTime.Now, 1; DateTime.Now.AddDays(1.0), 10 ]
Chart.Line [ for h in 1 .. 50 -> DateTime.Now.AddHours(float h), sqrt (float h) ]
Chart.Line [ for h in 1 .. 50 -> DateTime.Now.AddMinutes(float h), sqrt (float h) ]

Chart.Line(data,Title="Test Title")
Chart.Line(data,Title="Test Title").WithTitle(InsideArea=false)
Chart.Line(data,Title="Test Title").WithTitle(InsideArea=true)

Chart.Line(data,Title="Test Title")
   |> Chart.WithTitle(InsideArea=true)

Chart.Line(data,Name="Test Data")
   |> Chart.WithXAxis(Enabled=true,Title="X Axis")

Chart.Line(data,Name="Test Data") 
   |> Chart.WithXAxis(Enabled=false,Title="X Axis")

Chart.Line(data,Name="Test Data")
  .WithXAxis(Enabled=false,Title="X Axis")

Chart.Line(data,Name="Test Data")
  .WithXAxis(Enabled=true,Title="X Axis",Max=10.0, Min=0.0)
  .WithYAxis(Max=100.0,Min=0.0)

Chart.Line(data,Name="Test Data").WithLegend(Title="Hello")
Chart.Line(data,Name="Test Data").WithLegend(Title="Hello",Enabled=false)

Chart.Line(data,Name="Test Data").With3D()

// TODO: x/y axis labels are a bit small by default
Chart.Line(data,Name="Test Data",XTitle="hello", YTitle="goodbye")

Chart.Line(data,Name="Test Data").WithXAxis(Title="XXX")
Chart.Line(data,Name="Test Data").WithXAxis(Title="XXX",Max=10.0,Min=4.0)
                                 .WithYAxis(Title="YYY",Max=100.0,Min=4.0,Log=true)


Chart.Combine [ Chart.Line(data,Name="Test Data 1 With Long Name")
                Chart.Line(data2,Name="Test Data 2") ]                 
   |> Chart.WithLegend(Enabled=true,Title="Hello",Docking=ChartTypes.Docking.Left)

Chart.Combine [ Chart.Line(data,Name="Test Data 1")
                Chart.Line(data2,Name="Test Data 2") ]                 
   |> Chart.WithLegend(Docking=ChartTypes.Docking.Left, InsideArea=true)
   
Chart.Combine [ Chart.Line(data,Name="Test Data 1")
                Chart.Line(data2,Name="Test Data 2") ]                 
   |> Chart.WithLegend(InsideArea=true)
   

Chart.Rows 
     [ Chart.Line(data,Title="Chart 1", Name="Test Data 1")
       Chart.Line(data2,Title="Chart 2", Name="Test Data 2") ]                 
   |> Chart.WithLegend(Title="Hello",Docking=ChartTypes.Docking.Left)

 // TODO: this title and docking left doesn't work
Chart.Columns
     [ Chart.Line(data,Name="Test Data 1")
       Chart.Line(data2,Name="Test Data 2")]
   |> Chart.WithLegend(Title="Hello",Docking=ChartTypes.Docking.Left)


Chart.Combine [ Chart.Line(data,Name="Test Data 1")
                Chart.Line(data2,Name="Test Data 2") ]                 
   |> Chart.WithLegend(Title="Hello",Docking=ChartTypes.Docking.Bottom)

Chart.Line(data,Name="Test Data")
Chart.Line(data,Name="Test Data").WithLegend(Enabled=false)
Chart.Line(data,Name="Test Data").WithLegend(InsideArea=true)
Chart.Line(data,Name="Test Data").WithLegend(InsideArea=false)
Chart.Line(data).WithLegend().CopyAsBitmap()

Chart.Line(data)

Chart.Line(data,Name="Test Data").WithLegend(InsideArea=false)

Chart.Area(data)
Chart.Area(timeSeriesData)
Chart.Line(data)
Chart.Bar(data)
Chart.Bar(timeSeriesData)


Chart.Spline(data)
Chart.Spline(timeSeriesData)


Chart.Bubble(pointsWithSizes)
Chart.Bubble(pointsWithSizes)
  .WithMarkers(Style=ChartTypes.MarkerStyle.Star10)
Chart.Bubble(pointsWithSizes)
  .WithMarkers(Style=ChartTypes.MarkerStyle.Diamond)
Chart.Bubble(pointsWithSizes)
  .WithMarkers(Style=ChartTypes.MarkerStyle.Cross,Color=Color.Red)
Chart.Bubble(pointsWithSizes)
  .WithMarkers(Style=ChartTypes.MarkerStyle.Cross,Color=Color.Red,MaxPixelPointWidth=3)
Chart.Bubble(pointsWithSizes)
  .WithMarkers(Style=ChartTypes.MarkerStyle.Cross,Size=3)
Chart.Bubble(pointsWithSizes)
  .WithMarkers(Style=ChartTypes.MarkerStyle.Cross,PointWidth=0.1)
Chart.Bubble(pointsWithSizes)
  .WithMarkers(Style=ChartTypes.MarkerStyle.Cross,PixelPointWidth=3)

Chart.Bubble(pointsWithSizes).WithMarkers(Style=ChartTypes.MarkerStyle.Circle)
Chart.Bubble(pointsWithSizes).WithMarkers(Style=ChartTypes.MarkerStyle.Square)
Chart.Bubble(pointsWithSizes).WithMarkers(Style=ChartTypes.MarkerStyle.Star6)

Chart.Combine [ Chart.Bubble(pointsWithSizes,UseSizeForLabel=true) .WithMarkers(Style=ChartTypes.MarkerStyle.Circle)
                Chart.Bubble(pointsWithSizes2).WithMarkers(Style=ChartTypes.MarkerStyle.Star10) ]

Chart.Bubble(timedPointsWithSizes)

Chart.Candlestick(timeHighLowOpenClose)

Chart.Column(data)
Chart.Column(timeSeriesData)
Chart.Pie(Name="Pie", data=[ for i in 0 .. 10 -> i, i*i ])
Chart.Pie(Name="Pie", data=timeSeriesData)
Chart.Doughnut(data=[ for i in 0 .. 10 -> i, i*i ])
Chart.Doughnut(timeSeriesData)
Chart.FastPoint [ for x in 1 .. 10000 -> (rand(), rand()) ]
Chart.FastPoint timeSeriesData

Chart.Polar ([ for x in 1 .. 100 -> (360.0*rand(), rand()) ] |> Seq.sortBy fst)
Chart.Pyramid ([ for x in 1 .. 100 -> (360.0*rand(), rand()) ] |> Seq.sortBy fst)
Chart.Radar ([ for x in 1 .. 100 -> (360.0*rand(), rand()) ] |> Seq.sortBy fst)
Chart.Range ([ for x in 1.0 .. 10.0 -> (x, x + rand(), x-rand()) ])
Chart.RangeBar ([ for x in 1.0 .. 10.0 -> (x, x + rand(), x-rand()) ])
Chart.RangeColumn ([ for x in 1.0 .. 10.0 -> (x, x + rand(), x-rand()) ])
Chart.SplineArea ([ for x in 1.0 .. 10.0 -> (x, x + rand()) ])
Chart.SplineRange ([ for x in 1.0 .. 10.0 -> (x, x + rand(), x - rand()) ])
Chart.StackedBar ([ [ for x in 1.0 .. 10.0 -> (x, x + rand()) ]; 
                    [ for x in 1.0 .. 10.0 -> (x, x + rand()) ] ])
Chart.StackedColumn ([ [ for x in 1.0 .. 10.0 -> (x, x + rand()) ]; 
                       [ for x in 1.0 .. 10.0 -> (x, x + rand()) ] ])

Chart.StackedArea ([ [ for x in 1.0 .. 10.0 -> (x, x + rand()) ]; 
                     [ for x in 1.0 .. 10.0 -> (x, x + rand()) ] ])

Chart.StackedArea ([ [ for x in 1.0 .. 10.0 -> (DateTime.Now.AddDays x, x + rand()) ]; 
                     [ for x in 1.0 .. 10.0 -> (DateTime.Now.AddDays x, x + rand()) ] ])

Chart.StepLine(data,Name="Test Data").WithLegend(InsideArea=false)
Chart.StepLine(timeSeriesData,Name="Test Data").WithLegend(InsideArea=false)
Chart.Line(data,Name="SomeData").WithDataPointLabels(PointToolTip="Hello, I am #SERIESNAME") 

Chart.Stock(timeHighLowOpenClose)
Chart.ThreeLineBreak(data,Name="SomeData").WithDataPointLabels(PointToolTip="Hello, I am #SERIESNAME") 

Chart.Histogram([for x in 1 .. 100 -> rand()*10.],LowerBound=0.,UpperBound=10.,Intervals=10.)

// Example of .ApplyToChart() used to alter the settings on the window chart and to access the chart child objects.
// This can normally be done manually, in the chart property grid (right click the chart, then "Show Property Grid"). 
// This is useful when you want to try out carious settings first. But once you know what you want, .ApplyToChart() 
// allows programmatic access to the window properties. The two examples below are: IsUserSelectionEnabled essentially 
// allows zooming in and out along the given axes, and the longer fiddly example below does the same work as .WithDataPointLabels() 
// but across all series objects.
[ Chart.Column(data); 
  Chart.Column(data2) |> Chart.WithSeries.AxisType( YAxisType = Windows.Forms.DataVisualization.Charting.AxisType.Secondary ) ]
|> Chart.Combine
|> fun c -> c.WithLegend()
             .ApplyToChart( fun c -> c.ChartAreas.[0].CursorX.IsUserSelectionEnabled <- true )
             .ApplyToChart( fun c -> let _ = [0 .. c.Series.Count-1] |> List.map ( fun s -> c.Series.[ s ].ToolTip <- "#SERIESNAME (#VALX, #VAL{0:00000})" ) in () )
Fork me on GitHub