935 points · by pspeter3 · 5y ago · 141 comments
(
echo "<table class='charts-css bar show-labels show-heading'>"
echo "<caption>Size of Charts.css releases</caption>"
for version in $(curl -sS https://github.com/ChartsCSS/charts.css/releases | grep -o releases/tag/[0-9.]* | cut -d/ -f3 | tac); do
url=https://cdn.jsdelivr.net/npm/charts.css@$version/dist/charts.min.css
size=$(($(curl -sS "$url" | wc -c)/1024))
echo "<tr><th>v$version</th><td style='--size: calc($size/100)'>${size}KiB</td></tr>"
done
echo "</table><link rel=stylesheet href='$url'>"
) > size-chart.html
Result: https://jsfiddle.net/wcfez6oq/Since I couldn't easily find how large it was and wanted to try it out at the same time.
As an aside, a friend of mine has already arranged (as a joke) the rights to compile and remix any bash snippets I post in chat groups in a blog or book. Maybe I should write more about this, but then, it's probably most helpful exactly because I just drop it in places rather than writing a comprehensive work that nobody sits down to read. Still, I'm curious what the syntax/feature/pattern is that you found useful :)
syntax. Like, I knew about file redirection, but I didn't know you could group commands like that and redirect all their output with one operator. I would have had to do a bunch of appending with `>>`
You should definitely try mdbook if you want to keep it in a book format as it offers good fulltext search
And I found the entire script interesting I would definitely try this once I get to my laptop as I’m currently surfing HN on my phone
I actually thought it was number of downloads until I rechecked your script.
And even more. Really great that you van manipulate the elements as css. Most chart libs I’ve dealt with makes non-trivial customization impossible.
I’ll probably be building this in as Lowdefy blocks[1].
Just curious, did you consider just branding it as sparks.css / sprites.css or something? Going the spark / sprite route just sets the expectations a lot lower imo. Although congrats, you are really close to fully functional charts here! Really interested to see how far this can go.
[1] - https://lowdefy.com
Limitations, definitely needs a lot more connections for other DBs etc. Also we need first class support for auth and athorization, currently bring your own openid connect provider.
I’m definitely going to try this for one of my projects
This version (OP's) is way more polished and almost certainly more widely useful. But mine had the features of (a) being generated from markdown and (b) defaulting to a list presentation of the data under different styles so the data remained accessible.
Having more charting options that don't require javascript to do simple things is a good thing.
[0] https://rbitr.github.io/ChartS.css/ [1] https://news.ycombinator.com/item?id=23270581
I really wish this super small library named Chartist was more actively developed. It's only 10kb in size and generates SVG charts.
The huge benefit of SVG is that it's natively responsive and also prints extremely well. Wheres CSS doesn't
Edit: I also maintain my resume as responsive HTML. I haven’t taken the time to address print at all, but having previewed my own print rendering it definitely needs a lot of work before it’s print/PDF ready.
<link rel="stylesheet" media="print" href="print.css">EDIT: It looks like they have hover interaction, but it's not shown on the homepage.
Documentation is hard.
It is! But (if you’ll pardon my aside) increasingly my career/nerd goal is to promote documentation as an implementation source of truth. Documentation is hard because it’s seen as an additional task. But it’s possible to design interfaces where documentation is the API, or at least a first class part of it which determines API boundary behavior. It’s hard to do that upfront, but it’s great if you have the right primitives for it.
Having said that, I had to unfortunately abandon it because the ad-hoc control with Matplotlib [3] in Python is just infectious. Visual manipulations are far less easy to do in Vega. Being in JSON is also a restrictive though, because it is less interpretable by unstructured bots, where charts.css probably excels by design.
[1]: https://vega.github.io [2]: https://altair-viz.github.io [3]: https://matplotlib.org
[1] https://cryptomarketdepth.com/#graph
> Being in JSON is also a restrictive though, because it is less interpretable by unstructured bots, where charts.css probably excels by design.
What do you mean by this?
I meant to point out that Charts.css relies on having <table> elements in the HTML. Vega relies purely on JSON. This may or may not be of concern. For instance, if you care about bots crawling the website for semantic information, then perhaps the Charts.css way of operating on top of <table>s is preferred. A minor point though.
That said, it's a bit of a hack. The best kind of hack, the crazy smart kind, but still a hack. And as such, there are some visualization glitches here and there you wouldn't get with Canvas or SVG.
Still, such a cool idea. I love stretching technologies way beyond their original intent.
Introduction to data visualisation:
https://gss.civilservice.gov.uk/policy-store/introduction-to...
It's OK to use column charts where each column represents a category if and only if there's some ordinal nature along the x axis, i.e. if either of these are true:
A) The categories have a natural ordering (e.g. 'age group'), OR
B) The categories are ordered by their value on the y axis (i.e. the most popular 'reason for visiting the UK' is the first column, and the least popular on the right)
In other cases, a horizontal bar chart is preferable, as it does not lead the reader to mistakenly infer some ordinal relationship between the categories.
For learning how to choose a chart type, people should just buy Say it with charts (https://www.amazon.com/Say-Charts-Executives-Visual-Communic...), read it and complete the exercises.
BTW - another thing that bugs me about that chart: the y axis is labelled as 'thousands', but then the tick marks are labelled 2,000 to 16,000. It would better to use 2, 4, 6, ... for the tick marks, and label the axis as 'millions'. Even better would be to use percentages, and just mention N somewhere in the title.
Which of these charts is clearest? (top-left is the version in the linked guide, bottom-right is my preferred option): https://docs.google.com/spreadsheets/d/1JO2RXDQBJffWQ34QIi79...
Are there any sample graphs using more than 5 data points? I'd also want to see how this scales to reasonable blog-post level graphs which will probably be in the 30+ point range (a data point every five minutes covering a 3 hour range, or hourly for a week, both seem like reasonable minimum data sizes to be able to render well).
I love the potential accessibility benefits of using data tables directly styled like this.
Apart from different chart types, examples on how to rig data/image export will make this even more usefull.
I currently work on accessibility guidelines for visualisations at a national bureau of statistics. This came just at the right time for me as I'm exploring options to improve accessibility beyond the capabilities of libraries like highcharts, vega, charts.js etc. Don't hesitate to contact me. I'm very interested in the possibilities in this approach.
What do you find lacking in the accessibility of tables?
I haven't found a good way to highlight the data points in a table in such a way that it is easy to pick up by a screen reader. I would love a summary tag or similar to be part of the table in the same way we now have caption.
Anyway, I find the solution with tables way better than other html based chart solutions I've seen in regards to accessibility. They usually have a bunch of divs, spans and other tags that are really hard to follow.
Using tables seems so obvious now that I see it. I'm surprised I haven't seen it before. Good job!
We never got rid of 100% of it, but we did get really damn close using Blazor. Only ~180 lines of javascript interop is required for our entire solution last time I checked. This isn't trivial stuff either... We hand-rolled large file upload/download w/ progress, get client rect, get/set cookies, etc.
Originally developed by Mozilla, its focus is on beautiful and accurate charts, and displaying data in a good way.
The way this library works is the data is embedded in a table, which then gets converted to a chart by CSS - so if the CSS is disabled, the data is just presented as a table of numbers.
I'm not sure if SVG can be written so that it gracefully falls back like that. You could generate SVG from the table using JavaScript, of course, and just hide the table with JavaScript.
Given the weight and quality, I’d advise against this solution. With 70KB you might as well just load JS and get interactive graphs that don’t have rendering artifacts (line graphs look awful on my phone)
2. Can this be made interactive, e.g. on mouse-over show exact numbers? Without interactivity, it is still kinda lame
Make your CSS fit your HTML. Don't make HTML fit your CSS. This framework uses semantic native tables properly.
- - -
I’m on mobile so I can’t dig into the source, but they claim it’s using semantic HTML and the data is accessible. If you disagree with those claims, perhaps sharing your specific objections would make a better case than just vaguely crapping on the project.
The functionality behind this and others are simple and allow the user to fully stylize however they'd like.
0: https://github.com/mothepro/lit-chart 1: https://mothepro.github.io/lit-chart/
I will definitely keep an eye on it!
I really like the idea of applying a simple css style sheet and using my existing @foreach directives to build charts that look this good.
I had to double check the installation instructions 2x, because I was certain there was some javascript piece I had missed.
Library looks small (not sure how many KB) and full features for a basic charts library.
still a wip: //TODO: docs, tests and data.
I regret that I have but one upvote to give
If I missed something, can you point me to the right place in documentation? That's something that would make this useful.
There is nothing the CSS files of the project could do to help with that - as no help is needed :)
Currently when wanting a chart on a webpage I would fetch the data, transform it to the needed javascript array, add that to the HTML, and then initialize the javascript library painting the chart. With a CSS solution I'd just create a HTML-datatable instead, apply the needed classes and have it be rendered directly. It looks easier, faster and more accessible to me.
The example graphs are a bit flat, but that's just default styling. That's likely changeable with CSS, and animations can also be added that way, there are example for that linked in the docs.
Awesome project.
I’d highly doubt there were browsers supporting these CSS hacks but not supporting SVG.
With the HTML + CSS solution, all my program has to produce is a HTML table. Very easy.
With SVG my program has to create not just a data table, but the custom SVG code to paint the chart, down to each bar. I'm actually doing that on pc-kombo, https://www.pc-kombo.com/us/benchmark/games/cpu/compare?ids%... shows it, the image is SVG. But it's created with https://github.com/DannyBen/victor/, so my ruby code has to describe all the details of that image, including manually saying how each bar chart should look and where on the coordinate system the text goes. Even with the awesome victor library that wasn't all that easy.
Alternative is a JS library that produces the SVG code, but then it's exactly as complicated as with regular JS libraries, it just changes the output.
That's a non-starter for my usage unfortunately, as even degraded IE11 support is swing-able, but completely broken means we cannot use it. We're still seeing corporations and government agencies using IE11 on a regular basis.
Wikimedia claims 3.9% of their users are still IE11, we're closer to 10%, but we're also majority desktop rather than mobile users which is also really rare in 2020.