display only a time range with plotly.net

164 views Asked by At

I have a plotly.net graph with a lot of different shapes.

The X axis is a timeline and I would like to limit the display to a specific range of dates.

I could filter / clamp the data in each shape, etc but that seems like a lot of work compared to setting the display's range to specific values.

I can't find this in the plotly.net docs; does anyone know where that would be?

1

There are 1 answers

0
kMutagene On BEST ANSWER

You do not specify if the range of dates should be continuous, so i'll just assume it.

You can simply use the MinMax argument of the withXAxisStyle function like this:

open Plotly.NET

let dates = [for i in 1..10 -> System.DateTime.Now.AddYears(i)]
let values = [for i in 1..10 -> double i]

let range_start = System.DateTime.Now.AddYears(2)
let range_end = System.DateTime.Now.AddYears(3)

Chart.Line(
    x = dates, 
    y = values
)
|> Chart.withXAxisStyle(MinMax = (range_start, range_end))

As you can see, the dates range from 2025 untill 2026. although the original data goes until 2033.

the produced chart with a date range on the xAxis