Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vis

> 编程语言
Open source

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

7.8K stars0 likes2 views
WebsiteGitHub

About

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs

vis.js (deprecated!)

:exclamation: This project is not maintained anymore! (See Issue #4259 for details)
We welcome you to use the libraries from the visjs community from now on.


Vis.js is a dynamic, browser based visualization library. The library is designed to be easy to use, handle large amounts of dynamic data, and enable manipulation of the data. The library consists of the following components:

  • DataSet and DataView. A flexible key/value based data set. Add, update, and remove items. Subscribe on changes in the data set. A DataSet can filter and order items, and convert fields of items.
  • DataView. A filtered and/or formatted view on a DataSet.
  • Graph2d. Plot data on a timeline with lines or barcharts.
  • Graph3d. Display data in a three dimensional graph.
  • Network. Display a network (force directed graph) with nodes and edges.
  • Timeline. Display different types of data on a timeline.

The vis.js library was initially developed by Almende B.V.

Install

Install via npm:

bash
npm install vis

Install via bower:

bash
bower install vis

Link via cdnjs: https://cdnjs.com/libraries/vis

Or download the library from the github project: https://github.com/almende/vis.git.

Load

To use a component, include the javascript and css files of vis in your web page:

xml
<!DOCTYPE HTML>
<html>
<head>
  <script src="vis/dist/vis.min.js"></script>
  <link href="vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <script type="text/javascript">
    // ... load a visualization
  </script>
</body>
</html>

or load vis.js using require.js. Note that vis.css must be loaded too.

javascript
require.config({
  paths: {
    vis: 'path/to/vis/dist',
  }
});
require(['vis'], function (math) {
  // ... load a visualization
});

A timeline can be instantiated as:

javascript
var timeline = new vis.Timeline(container, data, options);

Where container is an HTML element, data is an Array with data or a DataSet, and options is an optional object with configuration options for the component.

Example

A basic example on loading a Timeline is shown below. More examples can be found in the examples directory of the project.

…

Build

To build the library from source, clone the project from github

bash
git clone git://github.com/almende/vis.git

The source code uses the module style of node (require and module.exports) to organize dependencies. To install all dependencies and build the library, run npm install in the root of the project.

bash
cd vis
npm install

Then, the project can be build running:

bash
npm run build

To automatically rebuild on changes in the source files, once can use

bash
npm run watch

This will both build and minify the library on changes. Minifying is relatively slow, so when only the non-minified library is needed, one can use the watch-dev script instead:

bash
npm run watch-dev

Custom builds

The folder dist contains bundled versions of vis.js for direct use in the browser. These bundles contain all the visualizations and include external dependencies such as hammer.js and moment.js.

The source code of vis.js consists of commonjs modules, which makes it possible to create custom bundles using tools like Browserify or Webpack. This can be bundling just one visualization like the Timeline, or bundling vis.js as part of your own browserified web application.

Note that hammer.js version 2 is required as of v4.

Prerequisites

Before you can do a build:

  • Install node.js and npm on your system: https://nodejs.org/
  • Install the following modules using npm: browserify, babelify, and uglify-js:
bash
[sudo] npm install -g browserify babelify uglify-js
  • Download or clone the vis.js project:
bash
git clone https://github.com/almende/vis.git
  • Install the dependencies of vis.js by running npm install in the root of the project:
bash
cd vis
npm install

Examples of custom builds

Example 1: Bundle only a single visualization type

For example, to create a bundle with just the Timeline and DataSet, create an index file named custom.js in the root of the project, containing:

javascript
exports.DataSet = require('./lib/DataSet');
exports.Timeline = require('./lib/timeline/Timeline');

Then create a custom bundle using browserify, like:

bash
browserify custom.js -t [ babelify --presets [es2015] ] -o dist/vis-custom.js -s vis

This will generate a custom bundle vis-custom.js, which exposes the namespace vis containing only DataSet and Timeline. The generated bundle can be minified using uglifyjs:

bash
uglifyjs dist/vis-custom.js -o dist/vis-custom.min.js

The custom bundle can now be loaded like:

xml
<!DOCTYPE HTML>
<html>
<head>
  <script src="dist/vis-custom.min.js"></script>
  <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
  ...
</body>
</html>

Example 2: Exclude external libraries

The default bundle vis.js is standalone and includes external dependencies such as hammer.js and moment.js. When these libraries are already loaded by the application, vis.js does not need to include these dependencies itself too. To build a custom bundle of vis.js excluding moment.js and hammer.js, run browserify in the root of the project:

bash
browserify index.js -t [ babelify --presets [es2015] ] -o dist/vis-custom.js -s vis -x moment -x hammerjs

This will generate a custom bundle vis-custom.js, which exposes the namespace vis, and has moment.js and hammer.js excluded. The generated bundle can be minified with uglifyjs:

bash
uglifyjs dist/vis-custom.js -o dist/vis-custom.min.js

The custom bundle can now be loaded as:

xml
<!DOCTYPE HTML>
<html>
<head>
  
  <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>

  
  <script src="dist/vis-custom.min.js"></script>
  <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
  ...
</body>
</html>

Example 3: Bundle vis.js as part of your (commonjs) application

When writing a web application with commonjs modules, vis.js can be packaged automatically into the application. Create a file app.js containing:

…

The application can be bundled and minified:

bash
browserify app.js -o dist/app-bundle.js -t babelify
uglifyjs dist/app-bundle.js -o dist/app-bundle.min.js

And loaded into a webpage:

xml
<!DOCTYPE HTML>
<html>
<head>
  <link href="node_modules/vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
  

  <script src="dist/app-bundle.min.js"></script>
</body>
</html>

Example 4: Integrate vis.js components directly in your webpack build

You can integrate e.g. the timeline component directly in you webpack build. Therefor you can e.g. import the component-files from root direcory (starting with "index-").

javascript
import { DataSet, Timeline } from 'vis/index-timeline-graph2d';

var container = document.getElementById('visualization');
var data = new DataSet();
var timeline = new Timeline(container, data, {});

To get this to work you'll need to add some babel-loader-setting to your webpack-config:

javascript
module: {
  module: {
    rules: [{
      test: /node_modules[\\\/]vis[\\\/].*\.js$/,
      loader: 'babel-loader',
      query: {
        cacheDirectory: true,
        presets: [ "babel-preset-es2015" ].map(require.resolve),
        plugins: [
          "transform-es3-property-literals", // #2452
          "transform-es3-member-expression-literals", // #2566
          "transform-runtime" // #2566
        ]
      }
    }]
  }
}

There is also an demo-project showing the integration of vis.js using webpack.

Test

To test the library, install the project dependencies once:

bash
npm install

Then run the tests:

bash
npm run test

License

Copyright (C) 2010-2017 Almende B.V. and Contributors

Vis.js is dual licensed under both

  • The Apache 2.0 License

and

  • The MIT License

Vis.js may be distributed under either license.

Issues· 815 open

View all issuesOpen on GitHub
  • #4039

    hideEdgesOnZoom capability for better performance of large gaphs

    Updated Jul 27, 2019
  • #2053

    new feature request to have horizontal and vertical connectors

    Updated Jul 22, 2019
  • #4308

    Showcase suggestion: libcolgraph

    Updated Jul 19, 2019
  • #1537

    Network: selectNode event not fired when calling .selectNodes()

    Updated Jul 8, 2019
  • #3459

    Network: how to select a node programmatically and fire an event

    Updated Jul 8, 2019
  • #3371

    Add option to disable long press for multiselect

    Updated Jul 4, 2019
  • #3651

    Graph2d zoom/pan problems

    Updated Jul 3, 2019
  • #3027

    [Timeline] Zoom state?

    Updated Jul 1, 2019
  • #3616

    [Timeline] hidden when start/end option not set

    Updated Jul 1, 2019
  • #3337

    Timeline: destroy() fails if groupTemplate option is overwritten

    Updated Jun 30, 2019

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言