Axis LabelStyle not working in FSharpChart?

285 Views Asked by At

I can't work out how to change the font on the Axes in FSharpChart.WithArea.

This is the shortest example I could come up with that displays the problem (on my machine, at least).

#r "System.Windows.Forms.DataVisualization.dll"
#r "MSDN.FSharp.Charting.dll"
open System.Windows.Forms.DataVisualization.Charting
open MSDN.FSharp.Charting
open System.Drawing

let font = new Font("Wingdings", 10.0F)

FSharpChart.FastLine([(0.,1.);(10., 10.)])
|> FSharpChart.WithArea.AxisX(LabelStyle = new LabelStyle(Font = font))
|> FSharpChart.WithCreate
1

There are 1 best solutions below

1
On

This is a bug in the library. If you want to fix it yourself, download the source code and find a line that defines typesToClone. It should look something like this:

let typesToClone = 
    [ typeof<LabelStyle>; typeof<Axis>; typeof<Grid>; typeof<TickMark>
      typeof<ElementPosition>; typeof<AxisScaleView>; typeof<AxisScrollBar>; ]

This defines a list of types whose properties are copied when creating a chart. The problem is that the name LabelStyle refers to a type in the F# Charting Library's source code rather than to the .NET chart controls type System.Windows.Forms.DataVisualization.Charting.LabelStyle. It can be fixed by using the full type name:

let typesToClone = 
    [ typeof<System.Windows.Forms.DataVisualization.Charting.LabelStyle>; 
      typeof<Axis>; typeof<Grid>; typeof<TickMark>
      typeof<ElementPosition>; typeof<AxisScaleView>; typeof<AxisScrollBar>; ]

I'll send this information to the current maintainers of the library to make sure the next version includes a fix for this. Thanks for reporting the issue!