diff --git a/docs/content/FurtherSamples.fsx b/docs/content/FurtherSamples.fsx index 9a887d3..564d085 100644 --- a/docs/content/FurtherSamples.fsx +++ b/docs/content/FurtherSamples.fsx @@ -188,4 +188,17 @@ Chart.Line(data,Name="SomeData").WithDataPointLabels(PointToolTip="Hello, I am # Chart.Stock(timeHighLowOpenClose) Chart.ThreeLineBreak(data,Name="SomeData").WithDataPointLabels(PointToolTip="Hello, I am #SERIESNAME") -Chart.Histogram([for x in 1 .. 100 -> rand()*10.],LowerBound=0.,UpperBound=10.,Intervals=10.) \ No newline at end of file +Chart.Histogram([for x in 1 .. 100 -> rand()*10.],LowerBound=0.,UpperBound=10.,Intervals=10.) + +// Example of .ApplyToChart() used to alter the settings on the window chart and to access the chart child objects. +// This can normally be done manually, in the chart property grid (right click the chart, then "Show Property Grid"). +// This is useful when you want to try out carious settings first. But once you know what you want, .ApplyToChart() +// allows programmatic access to the window properties. The two examples below are: IsUserSelectionEnabled essentially +// allows zooming in and out along the given axes, and the longer fiddly example below does the same work as .WithDataPointLabels() +// but across all series objects. +[ Chart.Column(data); + Chart.Column(data2) |> Chart.WithSeries.AxisType( YAxisType = Windows.Forms.DataVisualization.Charting.AxisType.Secondary ) ] +|> Chart.Combine +|> fun c -> c.WithLegend() + .ApplyToChart( fun c -> c.ChartAreas.[0].CursorX.IsUserSelectionEnabled <- true ) + .ApplyToChart( fun c -> let _ = [0 .. c.Series.Count-1] |> List.map ( fun s -> c.Series.[ s ].ToolTip <- "#SERIESNAME (#VALX, #VAL{0:00000})" ) in () ) \ No newline at end of file diff --git a/docs/content/fsharpcharting.md b/docs/content/fsharpcharting.md index 64eff13..95098f9 100644 --- a/docs/content/fsharpcharting.md +++ b/docs/content/fsharpcharting.md @@ -41,7 +41,7 @@ The following methods are used to style chart objects: * `WithTitle` * `WithXAxis` * `WithYAxis` - + * `ApplyToChart` Please [contribute](contributing.html) more documentation on the following topics: diff --git a/src/FSharp.Charting.fs b/src/FSharp.Charting.fs index 64e7cca..b569223 100644 --- a/src/FSharp.Charting.fs +++ b/src/FSharp.Charting.fs @@ -1145,6 +1145,7 @@ namespace FSharp.Charting let mutable data = ChartData.Values (NotifySeq.ignoreReset (NotifySeq.notifyOrOnce []), ChartValueType.Auto, "Item1", "Item2", "") let mutable margin = DefaultMarginForEachChart + let mutable customizationFunctions : (Chart -> unit) list = [] [] override x.GetHashCode() = 0 @@ -1165,6 +1166,11 @@ namespace FSharp.Charting member internal x.Chart with get() = chart.Value and set v = chart <- evalLazy v member internal x.Margin with get() = margin and set v = margin <- v member internal x.Name with get() = name and set v = name <- v + member internal x.CustomizationFunctions with get() = customizationFunctions + + member x.ApplyToChart ( fn : Chart -> unit ) = + customizationFunctions <- ( fn :: customizationFunctions ) + x /// Ensure the chart has a Title member internal x.ForceTitle() = @@ -3944,6 +3950,7 @@ namespace FSharp.Charting frm.Text <- ProvideTitle ch frm.Controls.Add(ctl) frm.Show() + ch.CustomizationFunctions |> List.rev |> List.map (fun fn -> fn ch.Chart) |> ignore ctl.Focus() |> ignore frm