2014-01-15 3 views
4

차트 컨트롤을 만들고 차트를 기존 폼에 배치하는 방법을 이해하지 못합니다. 웹에서 찾은 모든 예는 새로운 형식의 차트를 보여 주지만 기존 양식 중 하나에 차트를 추가하고 싶습니다.FSharp.Charting 그래프를 기존 폼에 표시하는 방법은 무엇입니까?

내가 이런 식으로 생각하고 있어요 :

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) 

감사합니다!

+0

'form.Controls.Add myChart' : 또한 참조 System.DrawingSystem.Windows.Forms에 필요합니까? – ildjarn

+0

원래 코드에서 컨테이너 대신 컨트롤을 의미했습니다. 아직도 작동하지 않습니다. 어딘가에 ChartControl과 같은 것이 있어야한다고 생각합니다. – vidi

답변

15

이것을 달성하려면 차트를 FSharp.Charting.ChartTypes.ChartControl에 랩핑하고 올바른 도킹을 처리해야합니다. 또한 FSharp.Charting의 ChartChartSystem.Windows.Forms.DataVisualization.Charting에서 섞어서는 안됩니다.

좋은 시작점은 현재 FSharp.Charting v0.90.5에서 작동하는 다음과 같은 완전한 기능의 샘플 일 수 있습니다.

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 
+0

고마워요! FSharp.Charting.ChartTypes 네임 스페이스의 ChartControl은 직관적이지 않습니다. 그리고 어떤 예도 찾을 수 없었습니다. – vidi

+1

아마도'WinForms' 앱에서'FSharp.Charting'의 사용에 너무 많은주의를 기울이지 않는 이유는 아마도 라이브러리의 가장 중요한 유스 케이스는 스크립팅입니다; 'WinForms'는 꽤 오래된 기술이고, 더 진보 된'WPF'는 예제 AFAIK를 가지고 있습니다. –

관련 문제