Question

I am using FSharp.Charting 0.87 to draw very basic chart of linear function. Is there a way to turn Y axis label back to normal position? In other words, can I have 'Y' oriented normally, not turned at 90 degrees?

Namely, I wonder if Axis.TextOrientation is exposed anywhere.

Here is the code:

#load "packages/FSharp.Charting.0.87/FSharp.Charting.fsx"    
open FSharp.Charting
open System.Drawing
Chart.Line([0,0;1,0;2,1;3,1;5,0; 6,0])
            .WithYAxis(Title = "Y", TitleAlignment = StringAlignment.Far)
            .WithXAxis(Title = "x", TitleAlignment = StringAlignment.Far)
            .ShowChart()
Was it helpful?

Solution

Here is the hack to get around the issue, in case anyone else needs it. In short, to get to the properties of Chart object, one has to create ChartControl first:

#load "packages/FSharp.Charting.0.87/FSharp.Charting.fsx"    
open FSharp.Charting
open FSharp.Charting.ChartTypes
open System.Drawing
open System.Windows.Forms

let chart = Chart.Line([0,0;1,0;2,1;3,1;5,0; 6,0])
                    .WithYAxis(Title = "Y", TitleAlignment = StringAlignment.Far)
                    .WithXAxis(Title = "x", TitleAlignment = StringAlignment.Far)
let ctrl = new ChartControl(chart, Dock=DockStyle.Fill)
let chartObj = ctrl.Controls |> Seq.cast<Control> |> Seq.pick (function | :? DataVisualization.Charting.Chart as x -> Some x | _-> None)
chartObj.ChartAreas.[0].AxisY.TextOrientation <- DataVisualization.Charting.TextOrientation.Horizontal
let form = new Form(Visible = true, TopMost = true, Width = 700, Height = 500)
form.Controls.Add(ctrl)
form.Show()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top