Skip to main content

charts.css.py brings charts.css to Python.

Project description

charts.css.py

As implied by its name, charts.css.py brings charts.css to Python.

Charts.css is a pure-CSS data visualization framework. It offers advantages over traditional JS-heavy chart libraries.

charts.css.py provides a pythonic API on top of charts.css, so that you can largely avoid working directly at HTML and CSS level.

Installation

pip install charts.css.py

Usage

charts.css.py process data by converting your 2-dimension number list into an HTML table, which is properly styled with CSS classes. Then you write such a string into your HTML page, together with <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/charts.css/dist/charts.min.css">, the visual representation will be rendered by browser.

For example, the following code snippet can convert a 2-dimension list into bar chart:

    from charts.css import bar, STYLESHEET
    chart = bar(
       [
            ["Continent", "1st year", "2nd year", "3rd year", "4th year", "5th year"],
            ["Asia", 20.0, 30.0, 40.0, 50.0, 75.0],
            ["Euro", 40.0, 60.0, 75.0, 90.0, 100.0],
        ],
        headers_in_first_row=True,
        headers_in_first_column=True,
        )
    open("output.html", "w").write(STYLESHEET + chart)

The output.html will be rendered in browser like this:

Sample output

Advanced Usage

There are currently 4 different charts implemented: bar, column, line, area. All those methods support these parameters to further customize the chart appearance. bar() and column() also support two extra parameters: stacked: boolean and percentage: boolean.

There is another experimental helper wrapper(...) which can be used to:

  • customize the display position of legend (you would need to use your HTML and CSS skill for this)
  • potentially mixed multiple charts and overlay them together.

Please read the unit test for more examples.

Lastly, this package also provides a command-line tool csv2chart. You can use it to convert csv file into an html file. For example, csv2chart sample.csv output.html. You can also run csv2chart -h to know all the parameters it supports.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

charts.css.py-0.2.0.tar.gz (6.8 kB view hashes)

Uploaded Source

Built Distribution

charts.css.py-0.2.0-py2.py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page