Skip to main content

module vis::Charts

Usage

import vis::Charts;

Synopsis

Simple data visualization using charts

Description

This modules provides a simple API to create charts for Rascal (numerical) data, based on chart.js. This library mirrors chart.js' JSON-based configuration API more or less one-to-one using AlgebraicDataTypes of Rascal. Documentation about chart.js should be easy to interpret.

This module is quite new and may undergo some tweaks in the coming time.

Examples

rascal>import vis::Charts;
ok
rascal>scatterChart([<x,x> | x <- [1..100]])

image


rascal>barChart([<"<x>",x> | x <- [1..100]])

image


rascal>lineChart([<"<x>",x> | x <- [1..100]])

image


rascal>pieChart([<"<x>",x> | x <- [1..100]])

image


Benefits

  • Easy to use for basic charting.
  • Uses chart auto colors extension for ease-of-use.
  • Support for 8 chart types including multiple chart data sets in one chart.
  • This API is open to extension via adding common keyword parameters for supporting any extension to the basic chart.js configuration.
  • You can roll your own HTML or Server based on the building blocks in this module to include and use extensions, or to combine different charts in the same view.

Pitfalls

  • Where num is asked, still rat values are not supported.
  • All real values must stay within JVM's double datatype
  • All int values must fit within JVM's long datatype

function scatterChart

Content scatterChart(lrel[num x,num y] v, str title="Scatterplot", ChartAutoColorMode colorMode=\dataset())

Content scatterChart(list[str] labels, lrel[num x,num y] values ..., str title="Scatterplots", ChartAutoColorMode colorMode=\dataset())

Content scatterChart(rel[num x ,num y] v, str title="Scatterplot", ChartAutoColorMode colorMode=\dataset())

Content scatterChart(list[str] labels, rel[num x,num y] values ..., str title="Scatterplots", ChartAutoColorMode colorMode=\dataset())

Synopsis

A scatterplot from a binary numerical relation.

function bubbleChart

Content bubbleChart(lrel[num x,num y, num r] v, str title="Scatterplot", ChartAutoColorMode colorMode=\data())

Content bubbleChart(list[str] labels, lrel[num x,num y, num r] values ..., str title="Scatterplots", ChartAutoColorMode colorMode=\data())

Content bubbleChart(rel[num x,num y, num r] v, str title="Scatterplot", ChartAutoColorMode colorMode=\data())

Content bubbleChart(list[str] labels, rel[num x,num y, num r] values ..., str title="Scatterplots", ChartAutoColorMode colorMode=\data())

Synopsis

A bubblechart from a binary numerical list relation.

Pitfalls

  • the radius is in raw pixels rather than scaled to the chart's axis

function barChart

Content barChart(rel[str label, num val] values, str title="Bar Chart", ChartAutoColorMode colorMode=\data())

Content barChart(lrel[str label, num val] values, str title="Bar Chart", ChartAutoColorMode colorMode=\data())

Content barChart(list[str] labels, rel[str label, num val] values..., str title="Bar Chart", ChartAutoColorMode colorMode=\dataset())

Content barChart(list[str] labels, lrel[str label, num val] values..., str title="Bar Chart", ChartAutoColorMode colorMode=\dataset())

Synopsis

A bar chart from labeled numbers

function lineChart

Content lineChart(rel[str label, num val] values, str title="Line Chart", ChartAutoColorMode colorMode=\data())

Content lineChart(lrel[str label, num val] values, str title="Line Chart", ChartAutoColorMode colorMode=\data())

Content lineChart(list[str] labels, rel[str label, num val] values..., str title="Line Chart", ChartAutoColorMode colorMode=\dataset())

Content lineChart(list[str] labels, lrel[str label, num val] values..., str title="Line Chart", ChartAutoColorMode colorMode=\dataset())

Synopsis

A line chart from labeled numbers

function polarAreaChart

Content polarAreaChart(rel[str label, num val] values, str title="Polar Area Chart", ChartAutoColorMode colorMode=\data())

Content polarAreaChart(lrel[str label, num val] values, str title="Polar Area Chart", ChartAutoColorMode colorMode=\data())

Content polarAreaChart(list[str] labels, rel[str label, num val] values..., str title="Polar Area Chart", ChartAutoColorMode colorMode=\dataset())

Content polarAreaChart(list[str] labels, lrel[str label, num val] values..., str title="Polar Area Chart", ChartAutoColorMode colorMode=\dataset())

Synopsis

A polar area chart from labeled numbers

function radarChart

Content radarChart(rel[str label, num val] values, str title="Radar Chart", ChartAutoColorMode colorMode=\data())

Content radarChart(lrel[str label, num val] values, str title="Radar Chart", ChartAutoColorMode colorMode=\data())

Content radarChart(list[str] labels, rel[str label, num val] values..., str title="Radar Chart", ChartAutoColorMode colorMode=\dataset())

Content radarChart(list[str] labels, lrel[str label, num val] values..., str title="Radar Chart", ChartAutoColorMode colorMode=\dataset())

Synopsis

A radar chart from labeled numbers

function pieChart

Content pieChart(rel[str label, num val] values, str title="Pie Chart", ChartAutoColorMode colorMode=\data())

Content pieChart(lrel[str label, num val] values, str title="Pie Chart", ChartAutoColorMode colorMode=\data())

Content pieChart(list[str] labels, rel[str label, num val] values..., str title="Pie Chart", ChartAutoColorMode colorMode=\dataset())

Content pieChart(list[str] labels, lrel[str label, num val] values..., str title="Pie Chart", ChartAutoColorMode colorMode=\dataset())

Synopsis

A pie chart from labeled numbers

function doughnutChart

Content doughnutChart(rel[str label, num val] values, str title="Doughnut Chart", ChartAutoColorMode colorMode=\data())

Content doughnutChart(lrel[str label, num val] values, str title="Doughnut Chart", ChartAutoColorMode colorMode=\data())

Content doughnutChart(list[str] labels, rel[str label, num val] values..., str title="Doughnut Chart", ChartAutoColorMode colorMode=\data())

Content doughnutChart(list[str] labels, lrel[str label, num val] values..., str title="Doughnut Chart", ChartAutoColorMode colorMode=\data())

Synopsis

A dougnut chart from labeled numbers

function chartDataSet

ChartDataSet chartDataSet(str label, rel[num x, num y] r)

ChartDataSet chartDataSet(str label, rel[num x, num y, num rad] r)

ChartDataSet chartDataSet(str label, lrel[num x,num y] r)

ChartDataSet chartDataSet(str label, lrel[num x, num y, num r] r)

function chartData

ChartData chartData(rel[str label, num val] v)

ChartData chartData(lrel[str label, num val] v)

ChartData chartData(list[str] labels, lrel[num x, num y] values...)

ChartData chartData(list[str] labels, lrel[num x , num y , num r] values...)

ChartData chartData(list[str] labels, rel[num x, num y] values...)

ChartData chartData(list[str] labels, rel[num x, num y, num r] values...)

ChartData chartData(list[str] setLabels, lrel[str label, num val] values...)

ChartData chartData(list[str] setLabels, rel[str label, num val] values...)

ChartData chartData(list[str] labels, list[num] values...)

ChartData chartData(str label, lrel[num x, num y] values)

ChartData chartData(str label, lrel[num x, num y, num r] values)

ChartData chartData(str label, rel[num x, num y] values)

ChartData chartData(str label, rel[num x, num y, num r] values)

data Chart

data Chart  
= chart(
ChartType \type = scatter(),
ChartOptions options = chartOptions(),
ChartData \data = chartData()
)
;

Synopsis

Toplevel chart structure

data ChartData

data ChartData  
= chartData(
list[str] labels=[],
list[ChartDataSet] datasets = []
)
;

Synopsis

Wrapper for a set of datasets, each with a label

data ChartDataSet

data ChartDataSet (
str label="",
list[str] backgroundColor=[],
list[str] borderColor=[],
list[str] color=[]
)
= chartDataSet(list[value] \data)
;

Synopsis

A dataset is a list of values to chart, with styling properties.

Description

The data field is a list of supported values, of which the constraints are not expressible by AlgebraicDataTypes. These are currently supported:

  • chart data point, with an without a radius
  • num, but within double precision (!) and no rat

data ChartDataPoint

data ChartDataPoint  
= point(num x, num y, num r = 0)
;

Synopsis

A data point is one of the types of values in a ChartDataSet

data ChartType

data ChartType  
= scatter()
| bar()
| bubble()
| line()
| polarArea()
| radar()
| pie()
| doughnut()
;

data ChartOptions

data ChartOptions  
= chartOptions(
bool responsive=true,
ChartPlugins plugins = chartPlugins()
)
;

data ChartPlugins

data ChartPlugins  
= chartPlugins(
ChartTitle title = chartTitle(),
ChartLegend legend = chartLegend(),
ChartColors colors = chartColors(),
ChartAutoColors autocolors = chartAutoColors()
)
;

data ChartAutoColors

data ChartAutoColors  
= chartAutoColors(
ChartAutoColorMode \mode = \data()
)
;

data ChartAutoColorMode

data ChartAutoColorMode  
= \data()
| \dataset()
;

data ChartLegend

data ChartLegend  
= chartLegend(
LegendPosition position = top()
)
;

data LegendPosition

data LegendPosition  
= \top()
| \bottom()
| \left()
| \right()
;

data ChartTitle

data ChartTitle  
= chartTitle(
str text="",
bool display = true
)
;

data ChartColors

data ChartColors  
= chartColors(
bool enabled = true
)
;

function chartServer

Response(Request) chartServer(ChartData theData, ChartType \type=\bar(), str title="Chart", ChartAutoColorMode colorMode=\data())

Response (Request) chartServer(Chart ch)

Synopsis

Utility function that constructs a Chart from ChartData and a given Chart type and a title.

Description

A chart has a typical default layout that we can reuse for all kinds of chart types. This function provides the template and immediately instantiates the client and the server to start displaying the chart in a browser.

function plotHTML

HTMLElement plotHTML()

Synopsis

default HTML wrapper for a chart