css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <link href='https://fonts.googleapis.com/css?family=Roboto:400,400italic&subset=latin,latin-ext,greek-ext,greek,cyrillic-ext,cyrillic,vietnamese' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Merriweather:400,400italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Alegreya+Sans+SC:400,400italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Tillana:400&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,400italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Comfortaa:400,&subset=latin,latin-ext,greek,cyrillic-ext,cyrillic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Inknut+Antiqua:400&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,400italic&subset=latin,latin-ext,greek-ext,greek,cyrillic-ext,cyrillic,vietnamese' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Krona+One&amp;subset=latin-ext" rel="stylesheet" type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Seymour+One&amp;subset=latin-ext" rel="stylesheet" type='text/css'>

	<h2> Simple line chart with microtext </h2>
	<small>Each line is labeled with microtext in multiple languages. Data, fonts and colors are semi-random, refresh page to re-run.</small></p>
<button onclick="actualLines.attr('visibility','hidden');"> Line off </button>
<button onclick="actualLines.attr('visibility','normal');"> Line on </button>
<button onclick="actualLines.attr('stroke-width',linewidth++);"> Fatter </button>
<button onclick="actualLines.attr('stroke-width',linewidth--);"> Thinner </button>
<button onclick="microText.attr('visibility','hidden'); "> Text off </button>
<button onclick="microText.attr('visibility','normal'); "> Text on </button>
<button onclick="fontsize++; microText.attr('font-size',fontsize); "> Bigger </button>
<button onclick="fontsize--; microText.attr('font-size',fontsize); "> Smaller </button> 
              		h2 {
			font-family: "Roboto Slab";
			font-weight: 700;
			color: #222277;
              //fonts loaded
fontlist=["Roboto", "Merriweather", "Roboto Slab", "Alegreya Sans SC", "Yanone Kaffeesatz", "Tillana", "Source Code Pro", "Comfortaa", "Inknut Antiqua", "Krona One", "Seymour One"];
//SAMPLE DATASET, 16 countries
dataset = [
      "Timeseries": []
      "Timeseries": []
			"Country":"Czech Republic",
			"French":"République tchèque",
			"German":"Tschechische Republik",
			"French":"Corée du Sud",
			"German":"Republik Korea",
var timeseriesMaxLen = Math.floor(Math.random()*60)+15;
var timeseriesVolatility = Math.random()*5.0;
var timeseriesMin = 9999; timeseriesMax = -9999;
var hexlist = '0123456789ABCDEF';
// make random data for the timeseries instead of the preset data
for (var i=1;i<dataset.length; i++) {
	// initial value is random, subsequent values based off prior value
	dataset[i].Timeseries[0] = Math.random()*1;
	for (var j=1;j<timeseriesMaxLen; j++) {
		dataset[i].Timeseries[j] = dataset[i].Timeseries[j-1] + 
	// get min/max/length of series
	timeseriesMin = Math.min( timeseriesMin, d3.min( dataset[i].Timeseries ) );
	timeseriesMax = Math.max( timeseriesMax, d3.max( dataset[i].Timeseries ) );
	// pick a font for this line
	dataset[i].fontfamily = fontlist[Math.floor(Math.random() * fontlist.length)];
	// create the string to use for the line
	dataset[i].microstring=" \00 " + dataset[i].Country;
	for (var j=0; j<50; j++) {
		prevmicro = dataset[i].microstring;
		dataset[i].microstring = prevmicro
					+ "--" + dataset[i].French
					+ "--" + dataset[i].German
					+ "--" + dataset[i].Country;
	// generate a random color for this line
	dataset[i].clr = "#";
	for (var j = 0; j < 6; j++) {
		  dataset[i].clr += hexlist[Math.floor(Math.random() * 16)];

// set up the drawing area
var w = 1000,
		h = 600,
		margin = 50;
fontsize = 8; linewidth = .1; letterspace = 1;
y = d3.scale.linear().domain([timeseriesMin, timeseriesMax]).range([0 + margin, h - margin]);
x = d3.scale.linear().domain([0, timeseriesMaxLen]).range([0 + margin, w - margin]);
var vis = d3.select("body")
			    .attr("width", w)
			    .attr("height", h);

var g = vis.append("svg:g")
			    .attr("transform", "translate(0, " + h + ")");


// parent (group) object for the lines and the text. 
// both the line and the microtext will inherit data from the parent	
var lineGroup = g.selectAll("lineGroup").data(dataset);
var lineObjects = lineGroup.enter()
// this is the line generation function - See Bostock d3.svg.line (i.e. paths)
var line = d3.svg.line()
		    .x(function(d,i) { return x(i); })
		    .y(function(d) { return -1 * y(d+ Math.random()*.01 ); })	
// the actual line geometry that get drawn
var actualLines = lineObjects
        // each line needs a unique id so we can associate the microtext with
				.attr("id", function(d,i) { return "path_"+ d.ISO; })
				.attr("stroke",function(d,i) { return d.clr; }) 
				.attr("stroke-width", linewidth)
				.attr("d",function(d) { return line(d.Timeseries); });
// the microtext
var microText = lineObjects
        // cross-reference to the line to put the text on the linepath
        // see also https://www.w3.org/TR/SVG/text.html#TextOnAPath
				.attr("xlink:href", function(d) { return "#path_" + d.ISO; })
				.attr("fill",   function(d,i) { return d.clr; })
				.attr("letter-spacing", letterspace)
				.attr("startOffset", function(d,i) { return -i*3.5; }) 
				.attr("font-family", function(d) { return d.fontfamily; })
				.text( function(d) { return d.microstring });
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................