Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- serveChart :: Port -> Chart -> IO ()
- serveDynamicChart :: Port -> ((Chart -> IO ()) -> IO ()) -> IO ()
- autoChart :: forall row. (ChartRowHeaderAuto row, ChartRowAuto row) => ChartOptions -> ChartStyle -> [row] -> Chart
- autoChartWithHeaders :: forall row. ChartRowAuto row => ChartOptions -> ChartStyle -> [Column] -> [row] -> Chart
- buildChart :: ChartOptions -> ChartStyle -> [Column] -> [[Value]] -> Chart
- defaultChartOptions :: ChartOptions
- data ChartOptions = ChartOptions Value
- data Chart
- data Column
- data ChartStyle
- type ChartRowAuto a = (ADT a, Constraints a ToJSON)
- type ChartRowHeaderAuto a = Constraints a ChartColumn
- class ChartColumn a where
- columnHeader :: Proxy a -> Column
Serving Charts
serveDynamicChart :: Port -> ((Chart -> IO ()) -> IO ()) -> IO () Source #
Serve a chart on the given port. The application can update the chart using the given handler.
Creating Charts
Automatic Charts
autoChart :: forall row. (ChartRowHeaderAuto row, ChartRowAuto row) => ChartOptions -> ChartStyle -> [row] -> Chart Source #
Create a chart from the provided options, style, and data by inferring column header types.
Prefer autoChartWithHeaders
when you know your column headers up front.
E.g. The following generates a 2-series bar chart with 4 sections, A, B, C, D
myAutoChart :: Chart myAutoChart = autoChart defaultChartOptions BarChart myData where myData :: [(T.Text, Float, Int)] myData = [ (A, 16, 20) , (B, 11, 23) , (C, 9, 25) , (D, 8, 34) ]
autoChartWithHeaders :: forall row. ChartRowAuto row => ChartOptions -> ChartStyle -> [Column] -> [row] -> Chart Source #
Create a chart from the provided options, style, and data, but use the explicitly provided column headers and types.
E.g. The following generates a 2-series bar chart with 4 sections, A, B, C, D
myAutoChart :: Chart myAutoChart = autoChartWithHeaders defaultChartOptions BarChart headers myData where headers :: [Column] headers = [StringColumn Series, NumberColumn Successes, NumberColumn Inconclusive] myData :: [(T.Text, Float, Int)] myData = [ (A, 16, 20) , (B, 11, 23) , (C, 9, 25) , (D, 8, 34) ]
Manual Charts
buildChart :: ChartOptions -> ChartStyle -> [Column] -> [[Value]] -> Chart Source #
Construct a chart.
e.g.
myChart :: Chart myChart = buildChart defaultChartOptions BarChart [StringColumn Year, NumberColumn Population] [ [ String "2004", Number 1000 ] , [ String "2005", Number 1170 ] , [ String "2006", Number 660 ] , [ String "2007", Number 1030 ] ]
Chart Options
defaultChartOptions :: ChartOptions Source #
Empty chart options
data ChartOptions Source #
I plan to make this typesafe for each partiular chart type but that's a LOT of work, so for now it's just free-form, if you'd actually use this, please make an issue on Github so I know folks need this behaviour :)
Find your chart in the chart gallery to see which options it will accept.
https://developers.google.com/chart/interactive/docs/gallery
Instances
ToJSON ChartOptions Source # | |
Defined in Charts.Internal.Chart toJSON :: ChartOptions -> Value # toEncoding :: ChartOptions -> Encoding # toJSONList :: [ChartOptions] -> Value # toEncodingList :: [ChartOptions] -> Encoding # |
Assorted Types
The primary chart type.
Valid Column types. Each "data" column also accepts a column header. Role columns do not.
See https://developers.google.com/chart/interactive/docs/roles
NumberColumn Text | |
StringColumn Text | |
BoolColumn Text | |
DateColumn Text | |
DateTimeColumn Text | |
TimeOfDayColumn Text | |
AnnotationColumn | |
AnnotationTextColumn | |
CertaintyColumn | |
EmphasisColumn | |
IntervalColumn | |
ScopeColumn | |
StyleColumn | |
TooltipColumn | |
DomainColumn | This is typically inferred and explicitly |
DataColumn | This is typically inferred and explicitly |
data ChartStyle Source #
Supported chart types See https://developers.google.com/chart/interactive/docs/gallery
LineChart | |
Histogram | |
BarChart | |
ColumnChart | |
ScatterChart | |
AreaChart | |
PieChart | |
BubbleChart | |
SteppedAreaChart | |
CandlestickChart |
Instances
Eq ChartStyle Source # | |
Defined in Charts.Internal.Chart (==) :: ChartStyle -> ChartStyle -> Bool # (/=) :: ChartStyle -> ChartStyle -> Bool # | |
Ord ChartStyle Source # | |
Defined in Charts.Internal.Chart compare :: ChartStyle -> ChartStyle -> Ordering # (<) :: ChartStyle -> ChartStyle -> Bool # (<=) :: ChartStyle -> ChartStyle -> Bool # (>) :: ChartStyle -> ChartStyle -> Bool # (>=) :: ChartStyle -> ChartStyle -> Bool # max :: ChartStyle -> ChartStyle -> ChartStyle # min :: ChartStyle -> ChartStyle -> ChartStyle # | |
Show ChartStyle Source # | |
Defined in Charts.Internal.Chart showsPrec :: Int -> ChartStyle -> ShowS # show :: ChartStyle -> String # showList :: [ChartStyle] -> ShowS # | |
ToJSON ChartStyle Source # | |
Defined in Charts.Internal.Chart toJSON :: ChartStyle -> Value # toEncoding :: ChartStyle -> Encoding # toJSONList :: [ChartStyle] -> Value # toEncodingList :: [ChartStyle] -> Encoding # |
type ChartRowAuto a = (ADT a, Constraints a ToJSON) Source #
A constraint representing a type which can be converted into a chart row
This constraint is satisfied by tuple types containing JSON serializable types.
E.g. data rows of type (Text, Int, Float)
will infer a chart with a String column and two number
columns.
You shouldn't need to implement any instances of this constraint yourself.
type ChartRowHeaderAuto a = Constraints a ChartColumn Source #
A constraint that a column-type can be determined for all elements of the provided tuple type.
class ChartColumn a where Source #
Class representing types for which a column type can be inferred.
You can implement your own instances for this if you like, but generally shouldn't need to.
columnHeader :: Proxy a -> Column Source #
Instances
ChartColumn Bool Source # | |
Defined in Charts.Internal.Auto | |
ChartColumn Double Source # | |
Defined in Charts.Internal.Auto | |
ChartColumn Float Source # | |
Defined in Charts.Internal.Auto | |
ChartColumn Int Source # | |
Defined in Charts.Internal.Auto | |
ChartColumn Scientific Source # | |
Defined in Charts.Internal.Auto columnHeader :: Proxy Scientific -> Column Source # | |
ChartColumn String Source # | |
Defined in Charts.Internal.Auto | |
ChartColumn Text Source # | |
Defined in Charts.Internal.Auto |