23 people like it.

Boxplot diagram using chart controls

The snippet shows how to use Microsoft Chart Controls (available in .NET 4.0 and for .NET 3.5) to draw a BoxPlot diagram. In this sample, we provide six statistics (Maxmimum, Minimum, Upper quartile, Lower quartile, Average and Median) about observations explicitly.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
#r "System.Windows.Forms.DataVisualization.dll"
open System.Windows.Forms
open System.Windows.Forms.DataVisualization.Charting

// Create a chart containing a default area and show it on a form
let chart = new Chart(Dock = DockStyle.Fill)
let form = new Form(Visible = true, Width = 700, Height = 500)
chart.ChartAreas.Add(new ChartArea("MainArea"))
form.Controls.Add(chart)

// Create series and add it to the chart
let series = new Series(ChartType = SeriesChartType.BoxPlot)
chart.Series.Add(series)

// Add data to the series in a loop
[| -12.7; 11.6; -8.3; 6.4; -2.5; -1.6 |]
|> Array.map box |> series.Points.AddY |> ignore
namespace System
namespace System.Windows
namespace System.Windows.Forms
namespace System.Windows.Forms.DataVisualization
namespace System.Windows.Forms.DataVisualization.Charting
val chart : Chart

Full name: Script.chart
Multiple items
type Chart =
  inherit Control
  new : unit -> Chart
  member AlignDataPointsByAxisLabel : unit -> unit + 3 overloads
  member Annotations : AnnotationCollection
  member AntiAliasing : AntiAliasingStyles with get, set
  member ApplyPaletteColors : unit -> unit
  member BackColor : Color with get, set
  member BackGradientStyle : GradientStyle with get, set
  member BackHatchStyle : ChartHatchStyle with get, set
  member BackImage : string with get, set
  member BackImageAlignment : ChartImageAlignmentStyle with get, set
  ...

Full name: System.Windows.Forms.DataVisualization.Charting.Chart

--------------------
Chart() : unit
type DockStyle =
  | None = 0
  | Top = 1
  | Bottom = 2
  | Left = 3
  | Right = 4
  | Fill = 5

Full name: System.Windows.Forms.DockStyle
field DockStyle.Fill = 5
val form : Form

Full name: Script.form
Multiple items
type Form =
  inherit ContainerControl
  new : unit -> Form
  member AcceptButton : IButtonControl with get, set
  member Activate : unit -> unit
  member ActiveMdiChild : Form
  member AddOwnedForm : ownedForm:Form -> unit
  member AllowTransparency : bool with get, set
  member AutoScale : bool with get, set
  member AutoScaleBaseSize : Size with get, set
  member AutoScroll : bool with get, set
  member AutoSize : bool with get, set
  ...
  nested type ControlCollection

Full name: System.Windows.Forms.Form

--------------------
Form() : unit
property Chart.ChartAreas: ChartAreaCollection
System.Collections.ObjectModel.Collection.Add(item: ChartArea) : unit
ChartAreaCollection.Add(name: string) : ChartArea
Multiple items
type ChartArea =
  inherit ChartNamedElement
  new : unit -> ChartArea + 1 overload
  member AlignWithChartArea : string with get, set
  member AlignmentOrientation : AreaAlignmentOrientations with get, set
  member AlignmentStyle : AreaAlignmentStyles with get, set
  member Area3DStyle : ChartArea3DStyle with get, set
  member Axes : Axis[] with get, set
  member AxisX : Axis with get, set
  member AxisX2 : Axis with get, set
  member AxisY : Axis with get, set
  member AxisY2 : Axis with get, set
  ...

Full name: System.Windows.Forms.DataVisualization.Charting.ChartArea

--------------------
ChartArea() : unit
ChartArea(name: string) : unit
property Control.Controls: Control.ControlCollection
Control.ControlCollection.Add(value: Control) : unit
val series : Series

Full name: Script.series
Multiple items
type Series =
  inherit DataPointCustomProperties
  new : unit -> Series + 2 overloads
  member AxisLabel : string with get, set
  member ChartArea : string with get, set
  member ChartType : SeriesChartType with get, set
  member ChartTypeName : string with get, set
  member EmptyPointStyle : DataPointCustomProperties with get, set
  member Enabled : bool with get, set
  member IsXValueIndexed : bool with get, set
  member Legend : string with get, set
  member MarkerStep : int with get, set
  ...

Full name: System.Windows.Forms.DataVisualization.Charting.Series

--------------------
Series() : unit
Series(name: string) : unit
Series(name: string, yValues: int) : unit
type SeriesChartType =
  | Point = 0
  | FastPoint = 1
  | Bubble = 2
  | Line = 3
  | Spline = 4
  | StepLine = 5
  | FastLine = 6
  | Bar = 7
  | StackedBar = 8
  | StackedBar100 = 9
  ...

Full name: System.Windows.Forms.DataVisualization.Charting.SeriesChartType
field SeriesChartType.BoxPlot = 28
property Chart.Series: SeriesCollection
System.Collections.ObjectModel.Collection.Add(item: Series) : unit
SeriesCollection.Add(name: string) : Series
module Array

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
val box : value:'T -> obj

Full name: Microsoft.FSharp.Core.Operators.box
property Series.Points: DataPointCollection
DataPointCollection.AddY([<System.ParamArray>] yValue: obj []) : int
DataPointCollection.AddY(yValue: float) : int
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore

More information

Link:http://fssnip.net/3f
Posted:13 years ago
Author:Tomas Petricek
Tags: charting , chart controls