Google DataVisualization을 사용자 정의하고 싶지만 컨트롤의 생성자를 매개 변수화하려고했지만 어떤 이유로 인해 inputDataTable
을 매개 변수로 전달할 때 작동하지 않는 것처럼 보입니다.Websharper/Web.Control 생성자 문제
module Example =
let headers = [|"Country"; "Population (mil)"; "Area (km2)" |]
let inputDataTable = [|
[|box "CN"; box 1234000; box 9640821|]
[|box "IN"; box 1133000; box 3287263|]
[|box "US"; box 304000; box 9629091|]
[|box "ID"; box 232000; box 1904569|]
[|box "BR"; box 187000; box 8514877|]
|]
코드는 웹 페이지에 차트를 생성 : 여기
내가 사용하는 기본 데이터입니다.let GeoChart headers inputDataTable =
Div []
|>! OnAfterRender (fun container ->
let dataFormatter = DefaultOptions.NumberFormatter ""
let options = DefaultOptions.GeoChart
let visualization = new GeoChart(container.Dom)
let data = Data.GeoMapData headers inputDataTable
dataFormatter.format(data, 1)
visualization.draw(data, options)
)
"예상 됨"컨트롤입니다.
type GoogleGeoChartViewer(headers, inputDataTable) =
inherit Web.Control()
[<JavaScript>]
override this.Body =
Google.Charts.GeoChart headers inputDataTable :> _
기본 템플릿을 사용한 테스트.
let HomePage =
let headers = Google.Example.headers
let inputDataTable = Google.Example.inputDataTable
Skin.WithTemplate "HomePage" <| fun ctx ->
[
Div [Text "HOME"]
Div [new Controls.EntryPoint()]
Div [new Controls.GoogleGeoChartViewer(headers, inputDataTable)]
Links ctx
]
그러나이 코드를 사용할 때 : 지오 차트가 표시되지 않습니다.
하지만 매개 변수 목록에서 inputDataTable
를 제거하고 사용하는 경우 :
let GeoChart headers =
Div []
|>! OnAfterRender (fun container ->
let dataFormatter = DefaultOptions.NumberFormatter ""
let options = DefaultOptions.GeoChart
let visualization = new GeoChart(container.Dom)
let inputDataTable = Example.inputDataTable
let data = Data.GeoMapData headers inputDataTable
dataFormatter.format(data, 1)
visualization.draw(data, options)
)
의미가 있습니다 ...
가 headers
배열 그러나 어떤 문제를 제기하지 않습니다.
아무도 어떤 일이 벌어지고 있는지 알 수 있습니까?
통찰력을 가져 주셔서 감사합니다.
설명해 주셔서 감사합니다. 필자는 제네릭 함수를 갖고 싶었 기 때문에지도에 원하는만큼의 시리즈를 추가 할 수있었습니다 (특히 지오 차트가 아닌, 강도 차트와 같은 다른 것들). 그래서 제가 obj [ ] []보다 직관적 인 (string * double ...) []. obj를 사용하여 주위를 둘러 보지 않도록하십시오. – user1251614