HelloWorldSample in F# not working

Feb 9, 2009 at 7:34 AM

Hi,
I am trying to implement the HelloWorldSample in F#. I have got to as far as getting an empty plot with just a legend.
In order to see the ChartPlotter, I've had to change the xaml code from

xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
to
xmlns:d3="clr-namespace:Microsoft.Research.DynamicDataDisplay;assembly=DynamicDataDisplay"

Currently I only get to see an empty chart, and I wonder what is missing from my implementation.
Here is the complete F# and xaml code.
Thanks

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d3="clr-namespace:Microsoft.Research.DynamicDataDisplay;assembly=DynamicDataDisplay"
    Title="Simplest plot sample" Height="243" Width="416">

    <d3:ChartPlotter Name="plotter">
        <d3:Header TextBlock.FontSize="20">
    Very simple chart
  </d3:Header>
  
  <d3:VerticalAxisTitle>Sine value</d3:VerticalAxisTitle>
  <d3:HorizontalAxisTitle>Sine argument</d3:HorizontalAxisTitle>
    </d3:ChartPlotter>
</Window>

 

#light

(*
#r "DynamicDataDisplay.dll"

#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0"
#r @"WindowsBase.dll"
#r @"PresentationCore.dll"
#r @"PresentationFramework.dll"
#r "System.Xml.dll"
*)

open System
open System.IO
open System.Text
open System.Windows
open System.Windows.Controls
open System.Windows.Data
open System.Windows.Markup
open System.Windows.Threading
open System.Xml
open System.Collections.Generic
open System.Threading
open System.Windows.Media
open Microsoft.Research.DynamicDataDisplay
open Microsoft.Research.DynamicDataDisplay.DataSources
open Microsoft.Research.DynamicDataDisplay.PointMarkers

let createWindow(wFileName: string) =
   using (XmlReader.Create(wFileName)) (fun stream -> (XamlReader.Load(stream)):?> Window )
  
let window =    createWindow       "..\\..\\MainWindow.xaml"
let plotter = window.FindName("plotter") :?>  ChartPlotter

window.Loaded.Add( fun _ -> ()
                            let temp = [| 0..1000|]
                            let x = Array.map (fun i -> (float i) * 0.1) temp
                            let y =Array.map (fun i -> Math.Sin i ) x
                            let xDataSource  = x.AsXDataSource<float>()
                            let yDataSource = y.AsYDataSource<float>()                         
                            let compositeDataSource = xDataSource.Join(yDataSource)                        
                            plotter.AddLineGraph(compositeDataSource, Colors.Goldenrod , 3., "Sine") |> ignore
                            plotter.FitToView()
                           
                      )

#if COMPILED
[<STAThread()>]
do
  let app = new Application() in

  app.Run(window) |> ignore
#endif 

Editor
May 5, 2009 at 12:29 PM
Hi,

Sorry for making you wait fot a long time)

Here is the F# code that is working:

#light

 

open System

open System.IO

open System.Text

open System.Windows

open System.Windows.Controls

open System.Windows.Data

open System.Windows.Markup

open System.Windows.Threading

open System.Collections.Generic

open System.Threading

open System.Windows.Media

open Microsoft.Research.DynamicDataDisplay

open Microsoft.Research.DynamicDataDisplay.DataSources

open Microsoft.Research.DynamicDataDisplay.PointMarkers

 

[<STAThread>]

do

    let window = new Window()

    let plotter = new ChartPlotter()

    window.Content <- plotter

    let temp = [|0..1000|]

    let x = Array.map (fun i -> (float i) * 0.1) temp

    let y = Array.map (fun i -> Math.Sin i ) x

    let xDataSource = x.AsXDataSource<float>()

    xDataSource.SetXMapping(fun f -> f);

    let yDataSource = y.AsYDataSource<float>()                         

    yDataSource.SetYMapping(fun f -> f);

    let compositeDataSource = xDataSource.Join(yDataSource)                        

    plotter.AddLineGraph(compositeDataSource, Colors.Goldenrod , 3., "Sine") |> ignore

    let app = new Application() in

    app.Run(window) |> ignore

 

As you can see, the difference is in calls of Set*Mapping methods of partial data sources. This has to be done with the version of D3 that is published because F# weirdly chooses which extensions method to use.

Regards,

Mikhail.