如何转回Y轴标签

时间:2013-11-06 21:03:26

标签: f# f#-interactive fsharpchart

我正在使用FSharp.Charting 0.87绘制非常基本的线性函数图表。有没有办法将Y轴标签转回正常位置?换句话说,我可以正常“Y”,而不是90度?

即,我想知道Axis.TextOrientation是否暴露在任何地方。

以下是代码:

#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()

1 个答案:

答案 0 :(得分:1)

以下是解决问题的方法,以防其他人需要它。简而言之,要获得Chart对象的属性,首先必须创建ChartControl:

#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()