data-viz-lab/elm-chart-builder/3.1.0

NOTE: the latest version is 7.0.2

Chart.HistogramBar

This is the histogram chart module from elm-chart-builder.

The histogram bar chart can both generate the histogram data automatically or accept preprocessed data.

Data Accessors

dataAccessor : Steps -> (data -> Float) -> AccessorHistogram data

The data accessor for generating a histogram. It takes a config that is separate from the general config, because it is only used when generating a histogram and not for bucketed pre-processed data.

steps : Steps
steps =
    [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 ]


dataAccessor =
    Histo.dataAccessor steps accessor
preProcessedDataAccessor : (data -> Bin Float Float) -> AccessorHistogram data

The data accessor for generating a histogram from pre-processed data. Meaning the data has already been bucketed and counted. values here is not used and always passed as an empty array.

preProcessedDataAccessor =
    Histo.preProcessedDataAccessor
        (\d ->
            { x0 = d.bucket
            , x1 = d.bucket + 0.1
            , values = []
            , length = d.count
            }
        )

Chart Initialization

init : RequiredConfig -> Config

Initializes the histogram bar chart with a default config.

Histo.init requiredConfig
    |> Histo.render ( data, accessor )

Chart Rendering

render : ( List data, AccessorHistogram data ) -> Config -> Html msg

Renders the histogram

Histo.init requiredConfig
    |> Histo.render ( data, accessor )

Configuration setters

withTable : Config -> Config

Build an alternative table content for accessibility

⚠ This is still work in progress and only a basic table is rendered with this option. For now it is best to only use it with a limited number of data points.

Histo.init requiredConfig
    |> Histo.withTable
    |> Histo.render ( data, accessor )
withDomain : ( Float, Float ) -> Config -> Config

Set the domain for the HistogramGenerator. All values falling outside the domain will be ignored.

Histo.init requiredConfig
    |> Histo.withDomain ( 0, 1 )
    |> Histo.render ( data, accessor )
withColor : Color -> Config -> Config

Set the histogram color

Histo.init requiredConfig
    |> Histo.withColor (Color.rgb255 240 59 32)
    |> Histo.render ( data, accessor )
withTitle : String -> Config -> Config

Sets an accessible title for the svg chart. Default value: ""

Histo.init requiredConfig
    |> Histo.withTitle "This is a chart"
    |> Histo.render ( data, accessor )
withDesc : String -> Config -> Config

Sets an accessible, long-text description for the svg chart. Default value: ""

Histo.init requiredConfig
    |> Histo.withDesc "This is an accessible chart, with a desc element"
    |> Histo.render ( data, accessor )
withYAxisTickFormat : (Float -> String) -> Config -> Config

Sets the formatting for the Y axis ticks.

Defaults to Scale.tickFormat

formatter =
    Numeral.format "0%"


Histo.init requiredConfig
    |> Histo.withYAxisTickFormat formatter
    |> Histo.render (data, accessor)
withYAxisTicks : List Float -> Config -> Config

Passes the tick values for the Y axis.

Defaults to elm-visualization Scale.ticks.

Histo.init requiredConfig
    |> Histo.withYAxisTicks [ 1, 2, 3 ]
    |> Histo.render ( data, accessor )
withYAxisTickCount : Int -> Config -> Config

Sets the approximate number of ticks for the Y axis.

Defaults to elm-visualization Scale.tickCount.

Histo.init requiredConfig
    |> Histo.withYAxisTickCount 5
    |> Histo.render ( data, accessor )
hideAxis : Config -> Config

Hide all axis.

Histo.init requiredConfig
    |> Histo.hideAxis
    |> Histo.render ( data, accessor )
hideYAxis : Config -> Config

Hide the Y aixs.

Histo.init requiredConfig
    |> Histo.hideYAxis
    |> Histo.render ( data, accessor )
hideXAxis : Config -> Config

Hide the X aixs.

Histo.init requiredConfig
    |> Histo.hideXAxis
    |> Histo.render ( data, accessor )