Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <!--Load the chart libraries. D3 and Echart. These in the <head></head>-->
<script charset="utf-8" src=""></script>
<script charset="utf-8" src="[email protected]/dist/echarts.min.js"></script>

<!--div container for the chart. this in the <body></body>-->
<div id="main"></div>


                /*just a bit of style*/
#main {
  width: 1000px;
  height: 600px;
  margin: auto;
  margin-top: 50px;



                /*An examble of Bar Chart usgin D3 and Apache Echart. Input data as CSV extract from: United Nations, Department of Economic and Social Affairs, Population Division (2018). World Urbanization Prospects: The 2018 Revision, Online Edition. Copyright © 2018 by United Nations, made available under a Creative Commons license CC BY 3.0 IGO: selection of the top 20 cities*/

//CityData is returned as an array containing the CSV data.

  "", d3.autotype).then(function (CityData) {
    //initialise Echarts in the Div id=main
    var myChartEchart = echarts.init(document.getElementById("main"), {
      width: 1000,
      height: 450
    }); //height is used to avoid cut the text on the Xaxis

    /* An example of 'option' as variable
             var labelOption = { 
             show: true,
             position: 'inside',
             rotate: 90,
             align: 'left',
             verticalAlign: 'middle',
             fontSize: 12,
             formatter: '{@pop1950} millions',

    // All the settings of the chart are provided in this variable
    var option = {
      title: {
        text: "World's Largest Urban Agglomerations 2020",
        textStyle: {
          color: "blue",
          fontSize: 22,
          fontWeight: "bold"
        subtext: "Population data UN World Urbanization Prospects",
        subtextStyle: {
          color: "coral",
          fontWeight: "bold"

      xAxis: {
        type: "category",
        axisLabel: {
          interval: 0,
          rotate: 30, //If the label names are too long you can manage this by rotating the label.
          fontSize: 9

      yAxis: {
        type: "value",
        name: "Population 2020 (millions)",
        nameLocation: "center",
        nameGap: 30,
        nameTextStyle: {
          align: "center"
        splitNumber: 10

      tooltip: {
        show: true

      legend: {
        data: ["CityName"]

      dataset: [
        // ref
          source: CityData
      series: [
          // ref
          type: "bar",
          showBackground: true,
          itemStyle: {
            color: "#ffcf7d",
            borderColor: "#ffac1f",
            borderWidth: 1.5,
            borderType: "dashed"
          barWidth: "70%",
          //label: labelOption, //option can be coded in external variable, see above. ref
          label: {
            show: true,
            position: "inside",
            rotate: 90,
            align: "left",
            verticalAlign: "middle",
            fontSize: 12,
            //formatter: '{@pop2035} millions', //pop value as strin
            formatter: function (params) {
              var pop2035_float = parseFloat(;

              return pop2035_float.toFixed(2) + ` millions`;
          encode: {
            x: "CityName",
            y: ["pop2035", "pop1950"],
            tooltip: ["pop2035", "pop1950"]

          tooltip: {
            formatter: function (params) {
              //as pop values are strings, we parsed them to Float to better control the number of decimal places
              var pop1950_float = parseFloat(;
              var pop2035_float = parseFloat(;

              return (
                `${}<br />
                                  Population 1950 :  ` +
                pop1950_float.toFixed(2) +
                ` millions <br />
                                  Population 2035 :  ` +
                pop2035_float.toFixed(2) +
                ` millions`

              //Uncomment the following return -and comment the previous one- to use pop values as strings in the TOOLTIP
                            return `${}<br />
                                      Population 1950: ${} millions <br />
                                      Population 2035: ${} millions`;
          animationDuration: 2000,
          animationEasing: "elasticOut" //

    // All the above is applied to the chart