Search code examples
f#deedlefslab

F# deedle Series How do I get the name of the Key and Series for use in XPlot


I am plotting, using XPLot, a chart of type Table. If I do not specify a Chart.WithLables then the Table uses Column1 and Column2 as headers. My Series was created from a DataFrame (indexed on Column with header name: Date and has a Column with the header name of Close. Here is the code for getting the Series from the data frame:

`let closes =  cl?Close`

Since I know that the 1st column in the Chart: Table is the Series Key and the second column is value(s) of the Series. I can hard code the Chart.WithLabels as

// Chart type: Table of column Close 
closes
|> Chart.Table
|> Chart.WithOptions(Options(showRowNumber = true, page = "enable",    pageSize = 20)) 
|> Chart.WithLabels ["Date"; "Close"]

I am looking for a method to extract the name of the Key(Date) and the name of the values(Close). For a data frame I could use

cl.Columns.Keys

to get the Column headers. I can't find any equivalent for a Series. I would like to code the Chart.WithLabels like

Chart.WithLabels [closes.KeyName; closes.Name]

Solution

  • Unlike a frame, Deedle series does not store a name for the key and values.

    If you want to write a reusable function, you will need to pass the names as additional parameters, or you can pass a data frame with a single column to your function.

    I would probably write something like:

    let plotSeriess label data =
      data
      |> Chart.Table
      |> Chart.WithOptions(Options(showRowNumber = true, page = "enable",    pageSize = 20)) 
      |> Chart.WithLabels ["Date"; label]