Skip to content

Commit f52ba52

Browse files
committed
Docs: Area - bar - box plot charts
1 parent e124efe commit f52ba52

File tree

8 files changed

+134
-126
lines changed

8 files changed

+134
-126
lines changed

docs/content/3d-scatter-plots.fsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ let z = [19; 26; 55;]
2020
(*** define-output:scatter3d_1 ***)
2121
Chart.Scatter3d(x,y,z,StyleOption.Mode.Markers)
2222
|> Chart.withX_AxisStyle("my x-axis")
23+
|> Chart.withY_AxisStyle("my y-axis")
24+
|> Chart.withZ_AxisStyle("my z-axis")
2325
|> Chart.withSize(800.,800.)
2426

2527
(*** include-it:scatter3d_1 ***)

docs/content/area-plots.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ Chart.Area(x,y)
2626
(*** define-output:area2 ***)
2727
Chart.SplineArea(x,y)
2828
(*** include-it:area2 ***)
29-
|> Chart.Show
29+
3030

docs/content/bar-charts.fsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,39 @@
55
(**
66
# FSharp.Plotly: Pie and Doughnut Charts
77
8-
*Summary:* This example shows how to create pie and doughnut charts in F#.
8+
*Summary:* This example shows how to create bar and a column charts in F#.
99
10-
A pie or a doughnut chart can be created using the `Chart.Pie` and `Chart.Doughnut` functions.
11-
When creating pie or doughnut charts, it is usually desirable to provide both labels and
12-
values.
10+
A bar chart or bar graph is a chart that presents grouped data with rectangular bars with
11+
lengths proportional to the values that they represent. The bars can be plotted vertically
12+
or horizontally. A vertical bar chart is called a column bar chart.
1313
*)
1414

1515
open FSharp.Plotly
1616

17-
let yValues = [20; 14; 23;]
18-
let xValues = ["Product A"; "Product B"; "Product C";]
19-
let labels = ["27% market share"; "24% market share"; "19% market share";]
20-
21-
(*** define-output:pie1 ***)
22-
Chart.Bar(xValues,yValues,Labels=labels,Opacity=0.3,Marker=Options.Marker(Color="rgba(222,45,38,0.8)"))
23-
|> Chart.withSize(500.,500.)
24-
(*** include-it:pie1 ***)
25-
|> Chart.Show
17+
let values = [20; 14; 23;]
18+
let keys = ["Product A"; "Product B"; "Product C";]
19+
let labels = ["27% market share"; "24% market share"; "19% market share";]
20+
21+
(*** define-output:bar1 ***)
22+
Chart.Column(keys,values,Labels=labels,Opacity=0.3,Marker=Options.Marker(Color="rgba(222,45,38,0.8)"))
23+
(*** include-it:bar1 ***)
24+
25+
(*** define-output:bar2 ***)
26+
Chart.Bar(keys,values)
27+
(*** include-it:bar2 ***)
28+
29+
30+
(**
31+
32+
## Stacked bar chart or column charts
33+
The following example shows how to create a stacked bar chart by combining bar charts created by `Chart.StackedBar`
34+
*)
35+
2636

37+
(*** define-output:bar3 ***)
38+
[
39+
Chart.StackedBar(keys,values,Name="old");
40+
Chart.StackedBar(keys,[8; 21; 13;],Name="new")
41+
]
42+
|> Chart.Combine
43+
(*** include-it:bar3 ***)

docs/content/box-plots.fsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ let x = ["bin1";"bin2";"bin1";"bin2";"bin1";"bin2";"bin1";"bin1";"bin2";"bin1"]
1818

1919
(*** define-output:box1 ***)
2020
Chart.BoxPlot(x,y,Jitter=0.3,Boxpoints=StyleOption.Boxpoints.Outliers)
21-
//|> Chart.Show
2221
(*** include-it:box1 ***)

docs/tools/formatters.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let createFsiEvaluator root output =
4343

4444
| :? GenericChart.GenericChart as ch ->
4545
// Just return the inline HTML for a Plotly chart
46-
let html = GenericChart.toChartHtmlWithSize 760 500 ch
46+
let html = GenericChart.toChartHtmlWithSize 500 500 ch
4747
Some [InlineBlock <| html]
4848

4949
| _ -> None

src/FSharp.Plotly/Chart.fs

Lines changed: 81 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -199,88 +199,91 @@ type Chart =
199199
TraceObjects.Scatter()
200200
|> Options.Scatter(X = x,Y = y, Mode = mode',Fill=StyleOption.ToZero_y)
201201
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
202-
|> Options.ILine(Options.Line(?Color=Color,?Dash=Dash,?Width=Width,?Smoothing=Smoothing))
202+
|> Options.ILine(Options.Line(Shape=StyleOption.Shape.Spline,?Color=Color,?Dash=Dash,?Width=Width,?Smoothing=Smoothing))
203203
|> Options.IMarker(Options.Marker(?Color=Color,?Symbol=MarkerSymbol))
204204
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
205205
GenericChart.Chart (trace,None)
206206

207207

208208

209-
// /// Illustrates comparisons among individual items
210-
// static member Bar(x, y, ?Name,?Showlegend,?Color,?Opacity,?Labels,?Marker) =
211-
// let marker =
212-
// match Marker with
213-
// | Some m -> Options.Marker(?Color=Color) >> m
214-
// | None -> Options.Marker(?Color=Color)
215-
// let trace =
216-
// Bar()
217-
// |> Options.Bar(X = x,Y = y,
218-
// TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
219-
// Marker=marker,
220-
// ?Text=Labels)
221-
// GenericChart.Chart (trace,None)
222-
//
223-
//
224-
// /// Displays series of the same chart type as stacked bars.
225-
// static member StackedBar(x, y, ?Name,?Showlegend,?Color,?Opacity,?Labels,?Marker) =
226-
// let marker =
227-
// match Marker with
228-
// | Some m -> Options.Marker(?Color=Color) >> m
229-
// | None -> Options.Marker(?Color=Color)
230-
// let trace =
231-
// Bar()
232-
// |> Options.Bar(X = x,Y = y,
233-
// TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
234-
// Marker=marker,
235-
// ?Text=Labels)
236-
//
237-
// let layout = Options.Layout(Barmode=StyleOption.Barmode.Stack)
238-
// GenericChart.Chart (trace,Some [layout])
239-
//
240-
//
241-
//
242-
// /// Uses a sequence of columns to compare values across categories.
243-
// static member Column(x, y, ?Name,?Showlegend,?Color,?Opacity,?Labels,?Marker) =
244-
// let marker =
245-
// match Marker with
246-
// | Some m -> Options.Marker(?Color=Color) >> m
247-
// | None -> Options.Marker(?Color=Color)
248-
// let trace =
249-
// Bar()
250-
// |> Options.Bar(X = x,Y = y,
251-
// TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
252-
// Marker=marker,
253-
// ?Text=Labels,Orientation = StyleOption.Orientation.Horizontal)
254-
//
255-
// GenericChart.Chart (trace,None)
256-
//
257-
// /// Displays series of the same chart type as stacked columns.
258-
// static member StackedColumn(x, y, ?Name,?Showlegend,?Color,?Opacity,?Labels,?Marker) =
259-
// let marker =
260-
// match Marker with
261-
// | Some m -> Options.Marker(?Color=Color) >> m
262-
// | None -> Options.Marker(?Color=Color)
263-
// let trace =
264-
// Bar()
265-
// |> Options.Bar(X = x,Y = y,
266-
// TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
267-
// Marker=marker,
268-
// ?Text=Labels,Orientation = StyleOption.Orientation.Horizontal)
269-
//
270-
// let layout = Options.Layout(Barmode=StyleOption.Barmode.Stack)
271-
// GenericChart.Chart (trace,Some [layout])
272-
//
273-
// /// Displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum.
274-
// static member BoxPlot(?x,?y,?Name,?Showlegend, ?Color,?Opacity,?Whiskerwidth,?Boxpoints,?Boxmean,?Jitter,?Pointpos,?Line,?Marker) =
275-
// let trace =
276-
// Box()
277-
// |> Options.BoxPlot(?X=x, ?Y = y,
278-
// TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
279-
// ?Line=Line,?Marker=Marker,
280-
// ?Fillcolor=Color,?Whiskerwidth=Whiskerwidth,?Boxpoints=Boxpoints,
281-
// ?Boxmean=Boxmean,?Jitter=Jitter,?Pointpos=Pointpos)
282-
//
283-
// GenericChart.Chart (trace,None)
209+
/// Illustrates comparisons among individual items
210+
static member Column(keys, values, ?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
211+
let marker =
212+
match Marker with
213+
| Some m -> Options.Marker(?Color=Color) >> m
214+
| None -> Options.Marker(?Color=Color)
215+
let trace =
216+
Bar()
217+
|> Options.Bar(X = keys,Y = values)
218+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
219+
|> Options.IMarker(marker)
220+
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
221+
GenericChart.Chart (trace,None)
222+
223+
224+
/// Displays series of tcolumn chart type as stacked columns.
225+
static member StackedColumn(keys, values, ?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
226+
let marker =
227+
match Marker with
228+
| Some m -> Options.Marker(?Color=Color) >> m
229+
| None -> Options.Marker(?Color=Color)
230+
let trace =
231+
Bar()
232+
|> Options.Bar(X = keys,Y = values)
233+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
234+
|> Options.IMarker(marker)
235+
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
236+
let layout =
237+
Options.Layout(Barmode=StyleOption.Barmode.Stack)
238+
GenericChart.Chart (trace,None)
239+
|> GenericChart.addLayout layout
240+
241+
/// Illustrates comparisons among individual items
242+
static member Bar(keys, values, ?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
243+
let marker =
244+
match Marker with
245+
| Some m -> Options.Marker(?Color=Color) >> m
246+
| None -> Options.Marker(?Color=Color)
247+
let trace =
248+
Bar()
249+
|> Options.Bar(X = values,Y = keys,Orientation = StyleOption.Orientation.Horizontal)
250+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
251+
|> Options.IMarker(marker)
252+
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
253+
GenericChart.Chart (trace,None)
254+
255+
256+
/// Displays series of tcolumn chart type as stacked bars.
257+
static member StackedBar(keys, values, ?Name,?Showlegend,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Marker) =
258+
let marker =
259+
match Marker with
260+
| Some m -> Options.Marker(?Color=Color) >> m
261+
| None -> Options.Marker(?Color=Color)
262+
263+
let trace =
264+
Bar()
265+
|> Options.Bar(X = values,Y = keys,Orientation = StyleOption.Orientation.Horizontal)
266+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
267+
|> Options.IMarker(marker)
268+
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
269+
270+
let layout =
271+
Options.Layout(Barmode=StyleOption.Barmode.Stack)
272+
GenericChart.Chart (trace,None)
273+
|> GenericChart.addLayout layout
274+
275+
276+
277+
/// Displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum.
278+
static member BoxPlot(?x,?y,?Name,?Showlegend, ?Color,?Opacity,?Whiskerwidth,?Boxpoints,?Boxmean,?Jitter,?Pointpos,?Orientation) =
279+
let trace =
280+
Box()
281+
|> Options.BoxPlot(?X=x, ?Y = y,
282+
?Whiskerwidth=Whiskerwidth,?Boxpoints=Boxpoints,
283+
?Boxmean=Boxmean,?Jitter=Jitter,?Pointpos=Pointpos,?Orientation=Orientation,?Fillcolor=Color)
284+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
285+
286+
GenericChart.Chart (trace,None)
284287

285288
/// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format.
286289
/// That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.
@@ -313,7 +316,8 @@ type Chart =
313316
// Marker=Options.Marker(?Color=Color),
314317
// ?Textinfo=Textinfo,?Textposition=Textposition)
315318
// GenericChart.Chart (trace,None)
316-
//
319+
320+
317321
// /// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data as a whole.
318322
// static member Doughnut(values,?labels,?Name,?Showlegend,?Color,?Hole,?Hoverinfo,?Textinfo,?Textposition) =
319323
// let hole' = if Hole.IsSome then Hole.Value else 0.4

src/FSharp.Plotly/Options.fs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -193,44 +193,29 @@ type Options() =
193193
// Applies the styles to Bar()
194194
static member Bar
195195
(
196-
//plotType: string,
197-
?TraceOptions:TraceOptions<_>,
198-
// data
199196
?X : seq<#IConvertible>,
200-
?Y : seq<#IConvertible>,
201-
?Text : seq<#IConvertible>,
202-
197+
?Y : seq<#IConvertible>,
203198
?Marker: MarkerOptions,
204199
?R: _, ?T: _,
205200
?Error_y: ErrorOptions,
206201
?Error_x: ErrorOptions,
207202
//
208203
?Orientation
209204
) =
210-
(fun (bar:('T :> Bar)) ->
211-
//bar.set_type plotType
212-
205+
(fun (bar:('T :> Bar)) ->
213206
X |> Option.iter bar.set_x
214-
Y |> Option.iter bar.set_y
215-
// Text |> Option.iter bar.set_text -- temporarily
216-
//form scattern --> textposition |> Option.iter (StyleOption.TextPosition.toString >> bar.set_textposition)
217-
//form scattern --> mode |> Option.iter (StyleOption.Mode.toString >> bar.set_mode)
218-
//form scattern --> connectgaps |> Option.iter bar.set_connectgaps
219-
//form scattern --> fill |> Option.iter (StyleOption.Fill.toString >> bar.set_fill)
220-
//form scattern --> fillcolor |> Option.iter bar.set_fillcolor
207+
Y |> Option.iter bar.set_y
221208
R |> Option.iter bar.set_r
222209
T |> Option.iter bar.set_t
223210
Orientation |> Option.iter (StyleOption.Orientation.convert >> bar.set_orientation)
224211

225-
// Update
226-
//form scattern --> line |> Option.iter (updatePropertyValueAndIgnore bar <@ bar.line @>)
227-
Marker |> Option.iter (updatePropertyValueAndIgnore bar <@ bar.marker @>)
228-
//form scattern --> textfont |> Option.iter (updatePropertyValueAndIgnore bar <@ bar.textfont @>)
212+
// Update
213+
Marker |> Option.iter (updatePropertyValueAndIgnore bar <@ bar.marker @>)
229214
Error_x |> Option.iter (updatePropertyValueAndIgnore bar <@ bar.error_x @>)
230215
Error_y |> Option.iter (updatePropertyValueAndIgnore bar <@ bar.error_y @>)
231216

232217
// out ->
233-
bar |> (optApply TraceOptions)
218+
bar
234219

235220
)
236221

@@ -608,12 +593,10 @@ type Options() =
608593
// Applies the styles to Pie()
609594
static member Pie
610595
(
611-
?TraceOptions:TraceOptions<_>,
612596
?Values,
613597
?Labels,
614598
?Label0,
615599
?dLabel,
616-
?Marker,
617600
?Scalegroup,
618601
?Textinfo,
619602
?Textfont: FontOptions,
@@ -650,20 +633,19 @@ type Options() =
650633
Pullsrc |> Option.iter pie.set_pullsrc
651634

652635
// Update
653-
Marker |> Option.iter (updatePropertyValueAndIgnore pie <@ pie.marker @>)
636+
//Marker |> Option.iter (updatePropertyValueAndIgnore pie <@ pie.marker @>)
654637
Textfont |> Option.iter (updatePropertyValueAndIgnore pie <@ pie.textfont @>)
655638
Insidetextfont |> Option.iter (updatePropertyValueAndIgnore pie <@ pie.insidetextfont @>)
656639
Outsidetextfont |> Option.iter (updatePropertyValueAndIgnore pie <@ pie.outsidetextfont @>)
657640

658641
// out ->
659-
pie |> (optApply TraceOptions)
642+
pie
660643
)
661644

662645

663646
// Applies the styles to Box()
664647
static member BoxPlot
665-
(
666-
?TraceOptions:TraceOptions<_>,
648+
(
667649
?Y,
668650
?X,
669651
?X0,
@@ -674,8 +656,6 @@ type Options() =
674656
?Jitter,
675657
?Pointpos,
676658
?Orientation,
677-
?Line : LineOptions,
678-
?Marker : MarkerOptions,
679659
?Fillcolor,
680660
?xAxis,
681661
?yAxis,
@@ -700,12 +680,9 @@ type Options() =
700680
yAxis |> Option.iter boxPlot.set_yaxis
701681
Ysrc |> Option.iter boxPlot.set_ysrc
702682
Xsrc |> Option.iter boxPlot.set_xsrc
703-
// Update
704-
Line |> Option.iter (updatePropertyValueAndIgnore boxPlot <@ boxPlot.line @>)
705-
Marker |> Option.iter (updatePropertyValueAndIgnore boxPlot <@ boxPlot.marker @>)
706683

707684
// out ->
708-
boxPlot |> (optApply TraceOptions)
685+
boxPlot
709686
)
710687

711688
// Applies the styles to TraceObjects with IMapZ interface

src/FSharp.Plotly/TraceObjects.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,15 @@ module TraceObjects =
12981298
with get () = Option.get _marker
12991299
and set value = _marker <- Some value
13001300
member __.ShouldSerializemarker() = not _marker.IsNone
1301+
1302+
1303+
interface ITrace with
1304+
member __.``type``
1305+
with get () = Option.get _type
1306+
and set value = _type <- Some value
1307+
1308+
member __.ShouldSerializetype() = not _type.IsNone
1309+
13011310
interface ITraceInfo with
13021311
/// Sets the trace name. The trace name appear as the legend item and on hover.
13031312
member __.name

0 commit comments

Comments
 (0)