Code Monkey home page Code Monkey logo

vue-c3-table-wrapper's Introduction

Markup Charts

Charts are a useful tool for presenting data but are not very accessible for visually impaired users.

They can also make it difficult for users to make use of the raw data if they want to combine it with data from another source or collate it differently.

Demo

You can run the demo in docker by running

docker-compose up
# Should run a server on http://localhost:8080

Alternatively you can install and run the code locally as follows:

If you want to view the example you should run

npm install --include-dev

Then you can run the code with an npm http server

npm run serve

Compiles and minifies for production

npm run build

Lints and fixes files

npm run lint

Progressive enhancement

GDS uses progressive enhancement to build pages that work as raw HTML with JS added on top to improve the experience for some users.

Setup

You can install this and just add the app.js and table-chart.js to your html as shown in the index.html with table-chart.js in the document head and app.js inside the closing body tag.

You also need to load the npm installed versions of VueJS, C3 and D3. If you have a different dependency management process you could include these from there or from a CDN.

<link href="node_modules/c3/c3.css" rel="stylesheet">
<script src="node_modules/d3/dist/d3.min.js" charset="utf-8"></script>
<script src="node_modules/c3/c3.min.js"></script>
<script src="node_modules/vue/dist/vue.js"></script>
<script src="lib/js/table-chart.js"></script>

You then need to add an app id to the body and a <div class="chart-wrapper"...> around any tables you want to chart. See options in the use section below:

Approach

This repository uses VueJS and C3 to create charts from the data in a standard HTML table by adding some markup to the parent div of the table element.

Use

<div class="chart-wrapper"
             type="line"
             series="rows"
             x-axis="Months"
             y-axis="Volume"
             above="false"
             separate="false"
             smoothed="true"
             stacked="false"
             order="null"
             palette="govuk"
        >

    <table id="test-table" class="govuk-table">

The div attributes tell the code the type of chart to draw and how to read the table data.

You can chart the data by the rows or columns in the table.

Attributes: type

The type attribute specifies which chart type to draw

  • line (and spline)
  • area (and area-spline)
  • pie
  • donut
  • bar
  • or a number of other chart types described on the c3 site.

Attributes: series

You can draw charts with each chart series being a table row or a table column

  • rows
  • cols or columns

Attributes: x-axis and y-axis

For bar, line and area charts which draw axes you can specify what each axis is called.

Attributes: above

At the moment the chart(s) draw below the table unless you specify above="true" in which case they are inserted above the table.

I might change this to position so you can put them side by side in a 2 column layout.

Attributes: separate

You can draw a single chart with all series on one chart or you can set separate="true" to draw a separate chart of each series. With this option the charts are drawn smaller using a 2 column layout.

Attributes: smoothed

Rather than specifying chart types as spline or area-spline you can just specify line and area and set smoothed=true

This draws smooth curves between the points on the chart rather than straight lines.

Attributes: stacked

For areas, lines and bar charts you can choose to have the data side by side or stacked=true into a cummulative total

Attributes: order

By default data is rendered in the order it is shown in the table data.

If you want a pie chart ordered by biggest to smallest segment you can set order="desc"

Attributes: palette

There are a number of predefined palettes or you can pass a json list of double quoted hex values

palette='["#b1d581","#b10e1e"]'

Attributes: rotated

Uses C3's axes rotated property to print horizontal bar charts.

Attributes: reversed

For time series data you may want to list the table data in columns in descending order (recent first) but render the chart with time going left to right.

vue-c3-table-wrapper's People

Contributors

danjoneslf avatar lunarfish avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.