问题描述
我不了解如何创建图表控件并将图表放置在现有表单中.我在网上找到的所有示例都以一种新的形式显示了图表,但我想将图表添加到现有表格之一中.
I don't understand how to create a chart control and place the chart in an existing form. All the examples I found on the web show the chart in a new form but I would like to add the chart to one of my existing forms.
我在想这样的事情:
let form = new Form(Text="My form")
let lbl = new Label(Text="my label")
let chart = Chart.Area ["a", 10; "b", 20]
form.Controls.Add lbl
form.Controls.Add chart
// ---> The type 'ChartTypes.GenericChart' is not compatible with the type 'Control'
Application.Run(form)
谢谢!
推荐答案
为实现此目的,您应该将图表包装到FSharp.Charting.ChartTypes.ChartControl
中,并注意正确的对接.另外,您也不应将FSharp中的Chart
与来自System.Windows.Forms.DataVisualization.Charting
的Chart
混合使用.
In order to achieve this you should wrap your chart into FSharp.Charting.ChartTypes.ChartControl
and take care of correct docking. Also you should not mix Chart
from FSharp.Charting with Chart
from System.Windows.Forms.DataVisualization.Charting
.
一个很好的凝视点可能是以下与当前FSharp.Charting v0.90.5兼容的功能齐全的示例;还需要引用System.Drawing
和System.Windows.Forms
:
A good staring point may be the following fully functional sample that works with the current FSharp.Charting v0.90.5; also references are required to System.Drawing
and System.Windows.Forms
:
open System
open FSharp.Charting
open FSharp.Charting.ChartTypes
open System.Drawing
open System.Windows.Forms
[<STAThread; EntryPoint>]
let main args =
let myChart = [for x in 0.0 .. 0.1 .. 6.0 -> sin x + cos (2.0 * x)]
|> Chart.Line |> Chart.WithYAxis(Title="Test")
let myChartControl = new ChartControl(myChart, Dock=DockStyle.Fill)
let lbl = new Label(Text="my label")
let form = new Form(Visible = true, TopMost = true, Width = 700, Height = 500)
form.Controls.Add lbl
form.Controls.Add(myChartControl)
do Application.Run(form) |> ignore
0
这篇关于如何以现有形式显示FSharp.Charting图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!