question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for inline charts - 'sparklines'

See original GitHub issue

What problem does this feature solve?

The term ‘sparkline’ was first used by Edward Tufte, who defined a sparkline in this way:

A sparkline is a small intense, simple, word-sized graphic with typographic resolution. Sparklines mean that graphics are no longer cartoonish special occasions with captions and boxes, but rather sparkline graphics can be everywhere a word or number can be: embedded in a sentence, table, headline, map, spreadsheet, graphic. Data graphics should have the resolution of typography.

see https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR

In html, for a chart to be embedded as Tufte describes, then that chart must be inline; that is, it should have css style

display:inline

So in order to make a genuine sparkline with echarts, we need to be able to make the echart inline.

To attempt this, we can build the echart on an inline element - e.g. <span> instead of <div> The first complication this creates is that an inline element cannot be given height or width; so a sparkline created with echarts will need to get its height and width from the config; e.g (using svg):

echarts.init(element, null, {renderer: 'svg', height: 20, width 80})

When echarts generates the chart, we see this in the generated html:

<div style="overflow: hidden; position: relative; width: 80px; height: 20px; background: transparent; cursor: pointer;">
	<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="80" height="20" style="user-select: none; position: absolute; left: 0px; top: 0px;">

This object is not inline, because the generated <div> has display:block by default, and the generated <svg> has position:absolute

We can use css to reach into this generated html and change it, like this:

<style>
.sparkline div {
	display: inline
}
.sparkline svg {
	position:relative !important
}

where the echart is created on a span with class sparkline: <span class="sparkline"/>

In echarts 4.7, this workaround will give an inline chart. But it would be preferable to have this functionality available in echarts by configuration.

What does the proposed API look like?

Add a new member display to the configuration object passed to echarts.init()

display : ‘block’ or ‘inline’ - default is ‘block’

This setting causes the appropriate changes to the style attributes of the generated <div> and <svg>

e.g. sample use:

let config = {
	renderer: "svg",
	height: 40,
	width: 100,
	display: 'inline'
}

In html it will look like

<p>Here is my embedded<span id="mySparkline"/> echart</p>

where the echart is instantiated on the <span> mySparkline.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
plainheartcommented, May 29, 2020

I think it’s easy and practical to set display of echarts container(element). There is An example on CodePen

Is it necessary to be supported by ECharts?

image

0reactions
baharmf93commented, Sep 27, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use sparklines to show data trends - Microsoft Support
Format a Sparkline chart · Select Line, Column, or Win/Loss to change the chart type. · Check Markers to highlight individual values in...
Read more >
Support for inline charts - 'sparklines' · Issue #12714 - GitHub
The term 'sparkline' was first used by Edward Tufte, who defined a sparkline in this way: A sparkline is a small intense, simple,...
Read more >
jQuery Sparklines - Omnipotent.net
Adds jQuery 1.10.0 support. This jQuery plugin generates sparklines (small inline charts) directly in the browser using data supplied either inline in the ......
Read more >
Introducing A New Chart Type: Sparklines - Chartio
The sparkline can be considered a sibling to the common line chart. Rather than plotting multiple lines on a single set of axes,...
Read more >
Add small inline charts (aka Tufte's 'sparklines')
Just like inline code, I would like to create very small charts that show data within a line of text. This is inspired...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found