1

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
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
Benjol
  • 63,995
  • 54
  • 186
  • 268

1 Answers1

4

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!

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • I don't know if I'm doing something wrong, but with that, my snippet above complains that `System.Reflection.TargetException: Object does not match target type`. – Benjol Jul 27 '11 at 06:11