Last active
March 9, 2016 07:49
-
-
Save DiegoNolan/cea621f6abcb25e79fb2 to your computer and use it in GitHub Desktop.
ChartJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Chart | |
data LineData = LineData | |
{ labels :: [String] | |
, datasets :: [DataSet] | |
} | |
instance ToJSON LineData where | |
toJSON (LineData{..}) = | |
object | |
[ "labels" .= labels | |
, "datasets" .= datasets | |
] | |
data DataSet = DataSet | |
{ label :: String | |
, fillColor :: String | |
, strokeColor :: String | |
, pointColor :: String | |
, pointStrokeColor :: String | |
, pointHighlightFill :: String | |
, pointHighlightStroke :: String | |
, data_ :: [Int] | |
} | |
instance ToJSON DataSet where | |
toJSON (DataSet{..}) = | |
object | |
[ "label" .= label | |
, "fillColor" .= fillColor | |
, "strokeColor" .= strokeColor | |
, "pointColor" .= pointColor | |
, "pointStrokeColor" .= pointStrokeColor | |
, "pointHighlightFill" .= pointHighlightFill | |
, "pointHighlightStroke" .= pointHighlightStroke | |
, "data" .= data_ | |
] | |
lineChart :: Element -> LineData -> IO (JSRef Chart) | |
lineChart canvasId dat = do | |
jsData <- toJSVal_aeson dat | |
_lineChart canvasId jsData | |
foreign import javascript unsafe | |
"var ctx = $1.getContext('2d'); \ | |
\console.log(ctx); \ | |
\console.log(ctx.canvas.clientWidth); \ | |
\console.log(ctx.canvas.clientHeight); \ | |
\var chart = new Chart(ctx).Line($2, {}); \ | |
\$r = chart;" _lineChart :: Element -> JSVal -> IO (JSRef Chart) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment