0

我正在使用 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()
4

1 回答 1

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()
于 2013-11-07T15:54:42.967 回答