我正在使用 FSharpChart 在同一图形上打印移动平均线和股票交易量。问题是一个图形从 20 到 50 或多或少,另一个从 0 到 8000 万,所以当我将两者结合起来时,一个被拆分到底部,这是无用的。我可以在 Y 轴上有两个不同的刻度,以便两个图形正确“合并”吗?
问问题
223 次
2 回答
5
如果AxisType
将系列之一设置为 ,则可以执行此操作AxisType.Secondary
。当然,然后由您来确保轴标签、图例等清楚地表明哪些数据映射到了哪个比例。
open FSharp.Charting
open System.Windows.Forms.DataVisualization.Charting
let squaresChart = [ 1 .. 100 ] |> List.map (fun n -> (n, n*n)) |> Chart.Line
let cubesChart = [ 1 .. 100 ] |> List.map (fun n -> (n, n*n*n)) |> Chart.Line
let bad =
[ squaresChart
cubesChart ]
|> Chart.Combine
let good =
[ squaresChart
cubesChart |> Chart.WithSeries.AxisType(YAxisType = AxisType.Secondary) ]
|> Chart.Combine
坏的:
好的:
这行得通,但是在我为编写此答案所做的快速测试中,似乎 FSharp.Charting 存在一些错误,因此某些自定义项具有“传染性”。创建“好”图表后,即使我不想要辅助轴,现在也会出现:
// secondary axis sticks around
bad |> Chart.WithTitle(Text = "Why secondary axis?")
// now the title and the secondary axis *both* stick around!
Chart.Rows [bad; good]
于 2015-07-09T17:10:16.623 回答
2
据我所知,您不能Chart.Combine
使用独立比例绘制图表。但是,您可以使用不同的组合器将它们堆叠在一起,例如Chart.Rows
在下面的片段中
#I @"C:\code\packages\FSharp.Charting.0.90.12"
#load "FSharp.Charting.fsx"
open FSharp.Charting
open System
let parabola = [ for x in 1.0 .. 1.0 .. 10.0 -> (x, (x ** 2.0) * 1000.0 ) ]
let curve = [ for i in 0.0 .. 0.02 .. 2.0 * Math.PI -> (sin i, cos i * sin i) ]
Chart.Rows([Chart.Line(parabola); Chart.Line(curve)])
生成具有完全不同比例的成分的组合图表:
于 2015-07-09T04:29:05.923 回答