Created
June 14, 2013 15:21
-
-
Save nwolverson/5782692 to your computer and use it in GitHub Desktop.
Examples of using Visiblox Charts with F#, with a simple wrapper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Visiblox.FSharp.Charting | |
open Visiblox.Charts | |
open System.Collections.Generic | |
module Data = | |
let private ds (x: DataPoint<_,_> seq) = new DataSeries<_,_>(x) | |
let Point (x,y) = new DataPoint<_,_>(x,y) | |
let MultiValuePoint x ys = new MultiValuedDataPoint<_,_>(x, new Dictionary<_,_>(dict ys)) | |
let BandPoint (x, y1, y2) = MultiValuePoint x [upcast BandSeries.Lower, y2; upcast BandSeries.Upper, y1 ] :> DataPoint<_,_> | |
let HlocPoint (x, yhigh, ylow, yopen, yclose) = | |
MultiValuePoint x [upcast HlocSeries.High, yhigh; upcast HlocSeries.Low, ylow; | |
upcast HlocSeries.Open, yopen; upcast HlocSeries.Close, yclose] :> DataPoint<_,_> | |
let HlcPoint (x, yhigh, ylow, yclose) = | |
MultiValuePoint x [upcast HlocSeries.High, yhigh; upcast HlocSeries.Low, ylow; | |
upcast HlocSeries.Close, yclose] :> DataPoint<_,_> | |
let Series data = data |> Seq.map Point |> ds | |
let SeriesBand data = data |> Seq.map BandPoint |> ds | |
let SeriesHloc data = data |> Seq.map HlocPoint |> ds | |
let SeriesHlc data = data |> Seq.map HlcPoint |> ds | |
module Series = | |
open Data | |
let Line data = LineSeries(DataSeries=Series data) | |
let Point data = LineSeries(DataSeries=Series data, ShowPoints=true, ShowLine=false) | |
let Spline data = SplineSeries(DataSeries=Series data) | |
let Staircase data = StaircaseSeries(DataSeries= Series data) | |
let Bar data = BarSeries(DataSeries=Series data) | |
let Column data = ColumnSeries(DataSeries=Series data) | |
let Band data = BandSeries(DataSeries=SeriesBand data) | |
let Hloc data = HlocSeries(DataSeries=SeriesHloc data) | |
let Hlc data = HlcSeries(DataSeries=SeriesHlc data) | |
let Candlestick data = HlocSeries(DataSeries=SeriesHloc data) | |
let stack toDataSeries (series: ChartMultipleSeriesBase) data = | |
data |> Seq.map toDataSeries |> Seq.iter series.Series.Add | |
series | |
let StackedLine data = stack Line (StackedLineSeries()) data | |
let StackedBar data = stack Bar (StackedBarSeries()) data | |
let StackedColumn data = stack Column (StackedColumnSeries()) data | |
let RadialLine data = RadialLineSeries(DataSeries=Series data) | |
module Charts = | |
let ShowChart c = | |
let w = new System.Windows.Window() | |
do w.Content <- c | |
do w.Show() | |
c | |
let Chart series = | |
let c = new Chart() | |
c.Series.Add series | |
c | |
let Combine series = | |
let c = new Chart() | |
Seq.iter c.Series.Add series | |
c | |
let Line d = d |> Series.Line |> Chart | |
let Point d = d |> Series.Point |> Chart | |
let Spline d = d |> Series.Spline |> Chart | |
let Bar d = d |> Series.Bar |> Chart | |
let Column d = d |> Series.Column |> Chart | |
let Band d = d |> Series.Band |> Chart | |
let Hloc d = d |> Series.Hloc |> Chart | |
let Hlc d = d |> Series.Hlc |> Chart | |
let Candlestick d = d |> Series.Candlestick |> Chart | |
let StackedLine ds = ds |> Series.StackedLine |> Chart | |
let StackedBar ds = ds |> Series.StackedBar |> Chart | |
let StackedColumn ds = ds |> Series.StackedColumn |> Chart | |
(* Pie Charts! *) | |
let Pie d = new PieChart(DataSeries=Data.Series d) | |
(* Radial Charts! *) | |
let Radial series = | |
let c = new RadialChart() | |
Seq.iter c.Series.Add series | |
c | |
let RadialLine d = Radial [Series.RadialLine d] | |
let RadialLines ds = Radial (Seq.map Series.RadialLine ds) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "C:\Program Files (x86)\Visiblox\Visiblox Charts v4.0.4\Ultimate\Wpf\4.0\Visiblox.Charts.dll" | |
#r "System.Core" | |
#r "System.Xml.Linq" | |
#r "System.Windows" | |
#r "PresentationFramework" | |
#r "PresentationCore" | |
#r "WindowsBase" | |
#r "System.Xaml" | |
#load "Charting.fs" | |
open Visiblox.FSharp.Charting | |
open System.Windows | |
// Any value is printed by opening a window with a chart in it! | |
// Concept courtesty of FSharp.Charting | |
fsi.AddPrinter(fun (c:Visiblox.Charts.ChartBase) -> Charts.ShowChart c |> ignore; "(Chart)") | |
// Display a simple line chart | |
[for x in 1..10 -> x, x*x] |> Charts.Line | |
// Configure the chart before display | |
let c = | |
let c = [for x in 1.0 .. 0.1 .. 10.0 -> x, sin(x)] |> Charts.Line | |
c.Title <- "My Second Chart" | |
c | |
// A pie chart has a different Visiblox type entirely | |
["A", 1; "B", 24; "C", 72] |> Charts.Pie | |
let multiData = [for x in 1..5 -> [for y in 1..10 -> y, y*y*x]] | |
// Multiple series charted together | |
multiData |> List.map Series.Line |> Charts.Combine | |
// Stacked column series - for Visiblox this is one container series with multiple column series "inside" | |
multiData |> Charts.StackedColumn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment