Explore the API
  • .data(getData())
  • .color()
  • .paging()
  • .schema([{"key": "id", "name": "ID"}, {"key": "date", "name": "Date", "type": "date"}, {"key": "city", "name": "Place of purchase"}, {"key": "total", "name": "Total amount", "type": "number"}, {"key": "currency", "name": "Currency"}])
ID
Date
Place of purchase
Total amount
a4ac752019-09-11Copenhagen55.2
a865c22019-08-23Copenhagen34.7
8a31282019-10-01Copenhagen98.8
eaa4c32019-08-06Copenhagen94.2
31765a2019-10-12Oslo57.2
c57e1b2019-05-20Copenhagen41.9
54a6582019-05-26Reykjavík83.3
7c2f8f2019-04-23Oslo77.6
564fdb2019-02-13Copenhagen88.3
d3ae432019-06-19Copenhagen82.1
3bae2a2019-01-23Reykjavík1.7
4b67972019-07-05Oslo33.4
84b8d02019-11-07Copenhagen27.0
4551e32019-03-06Oslo5.4
9cfac32019-04-07Reykjavík9.3
9abe842019-09-21Stockholm49.4
712f4e2019-04-22Copenhagen30.4
8569fc2019-02-26Reykjavík85.0
f8f69b2019-10-07Stockholm83.4
de3c142019-06-03Stockholm8.5
aac7ec2019-10-01Copenhagen97.9
53241d2019-11-06Reykjavík68.3
69cf332019-12-01Reykjavík33.2
a19e402019-01-26Copenhagen33.6
f67afa2019-08-21Oslo57.3
aa5b512019-02-17Reykjavík90.1
d33d612019-11-18Oslo48.7
5351b72019-02-22Oslo29.6

description

Tables show data in its raw format organized in a matrix. They are ideal when details are important and no relationship between the data points is of interest. As implemented in dalian, columns can be sorted by clicking on the header.

code

generate data

// Samples are generated with ranjs:
// https://synesenom.github.io/ran/
function getData () {
  const hasCurrency = Math.random() < 0.5
  return Array.from({ length: ranjs.core.int(2, 30) }, () => ({
    id: ranjs.core.char('0123456789abcdef', 6).join(''),
    date: new Date(2019, ranjs.core.int(0, 11), ranjs.core.int(1, 28))
      .toISOString().substr(0, 10),
    city: ranjs.core.choice(['Copenhagen', 'Oslo', 'Stockholm', 'Reykjavík']),
    total: ranjs.core.float(100).toFixed(1),
    ...(hasCurrency && { currency: ranjs.core.choice(['DKK', 'NOK', 'SEK', 'ISK']) })
  }))
}

create chart

const table = dalian.Table('table', '#widget')
  .data(getData())
  .schema([
    {key: 'id', name: 'ID'},
    {key: 'date', name: 'Date', type: 'date'},
    {key: 'city', name: 'Place of purchase'},
    {key: 'total', name: 'Total amount', type: 'number'},
    {key: 'currency', name: 'Currency'}
  ])
  .width(WIDTH)
  .height(HEIGHT)
  .margins(40)
  .font.size(14)
  .mouse.over(k => table.highlight(`row-${k.row}`))
  .mouse.leave(() => table.highlight())
  .render()