Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

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.

HTML

              
                <div id="myChart">
  
  <form id="addNote">
    <input type="text">
    <input type="submit">
  </form>
  
</div>


              
            
!

CSS

              
                body {
  font-family: Arial;
  margin: 0;
}

#myChart {
  height: 500px;
  width: 600px;
  margin: 0 auto;
}

#addNote {
  opacity: 0;
  transition: .3s linear;
  background-color: #eee;
  padding: 25px;
  position: fixed;
  top: 25%;
  left: 40%;
  z-index: 9999;
  border-radius: 4px;
}

#addNote.open {
  opacity: 1;
}
              
            
!

JS

              
                var chartData = [1,2,3,4];

var myConfig = {
  type: "bar",
  title: {
    text: 'Click A Chart Node To Add Annotation'
  },
  plot: {
    selectionMode: 'multiple',
    selectedState: {
      backgroundColor: 'black'
    }
  },
  series: [
    {
      values: chartData
    }
  ]
};

var chart = zingchart.render({
  id: "myChart",
  data: myConfig
});
// Grabs the <form> element from the DOM
var form = document.querySelector('#addNote');
// Creates variables that will hold node_click x & y coordinates
var xValue = 0;
var yValue = 0;
// This function stores node_click x and y coordinates
chart.bind('node_click', function(e) {
  var nodeXValue = e.x;
  var nodeYValue = e.y;
  // Re-assigns variables to original xValue and yValue variables
  xValue = nodeXValue;
  yValue = nodeYValue;
  // Adds open class to our <form> element
  form.classList.add('open');  
});
// This event listener function fires when our <form> element is submitted
form.addEventListener('submit', function(e) {
  // Prevents a <form> element submit without a value
  e.preventDefault();
  // Grabs the <input> text value from the DOM and assigns to a variable
  var note = form.querySelector('input[type="text"]').value;
  // Creates a ZingChart label object from the <input> text value submitted
  zingchart.exec('myChart', 'addobject', {
    type: 'label',
    data: {
      text: note,
      x: xValue,
      y: yValue,
      backgroundColor: '#eee',
      padding: [10, 25],
      borderRadius: 4,
    }
  });
  // Removes open class form <form> element
  form.classList.remove('open');
})
              
            
!
999px

Console