Advertisement
Guest User

BokehJS example

a guest
Sep 13th, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.23 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="utf-8" />
  5.     <title>Complete Example</title>
  6.  
  7.     <script
  8.      type="text/javascript"
  9.      src="https://cdn.pydata.org/bokeh/release/bokeh-1.3.4.min.js"
  10.    ></script>
  11.     <script
  12.      type="text/javascript"
  13.      src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.3.4.min.js"
  14.    ></script>
  15.     <script
  16.      type="text/javascript"
  17.      src="https://cdn.pydata.org/bokeh/release/bokeh-tables-1.3.4.min.js"
  18.    ></script>
  19.     <script
  20.      type="text/javascript"
  21.      src="https://cdn.pydata.org/bokeh/release/bokeh-gl-1.3.4.min.js"
  22.    ></script>
  23.     <script
  24.      type="text/javascript"
  25.      src="https://cdn.pydata.org/bokeh/release/bokeh-api-1.3.4.min.js"
  26.    ></script>
  27.  
  28.     <script>
  29.       //The order of CSS and JS imports above is important.
  30.     </script>
  31.     <script>
  32.       // arrays to hold data
  33.       const source = new Bokeh.ColumnDataSource({
  34.         data: { x: [1, 2, 3], y: [1, 2, 1] }
  35.       });
  36.  
  37.       // make the plot and add some tools
  38.       const tools = "pan,crosshair,wheel_zoom,box_zoom,reset,save";
  39.  
  40.       const plot = Bokeh.Plotting.figure({
  41.         title: "Example of Random data",
  42.         tools: tools,
  43.         height: 300,
  44.         width: 300
  45.       });
  46.  
  47.       const scatterData = plot.line(
  48.         { field: "x" },
  49.         { field: "y" },
  50.         {
  51.           source: source,
  52.           line_width: 2
  53.         }
  54.       );
  55.  
  56.       // Show the plot, appending it to the end of the current
  57.       // section of the document we are in.
  58.       Bokeh.Plotting.show(plot);
  59.  
  60.       function addPoint() {
  61.         // The data can be added, but generally all fields must be the
  62.         // same length.
  63.         source.data.x.push(Math.random());
  64.         source.data.y.push(Math.random());
  65.         // Also, the DataSource object must be notified when it has changed.
  66.         source.change.emit();
  67.       }
  68.  
  69.       const addDataButton = document.createElement("Button");
  70.       addDataButton.appendChild(document.createTextNode("Add Some Data!!!"));
  71.       document.currentScript.parentElement.appendChild(addDataButton);
  72.       addDataButton.addEventListener("click", addPoint);
  73.     </script>
  74.   </head>
  75.  
  76.   <body>
  77.   </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement