【问题标题】:Vis.js timeline with polymer error : Something is wrong with the Timeline scale带有聚合物错误的 Vis.js 时间线:时间线刻度有问题
【发布时间】:2018-03-18 00:06:13
【问题描述】:

我想使用polymervis.js 时间线创建时间线Web 组件。

聚合物元素代码

<template>
    <div id="visualization" style="height: 100%;width: 100%;border: 1px solid black"></div>
</template>
<link href="http://visjs.org/dist/vis.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.0/vis.js"></script>
<script>
    // register an element
    MyElement = Polymer({

        is: 'legacy-element',

        ready: function () {
            const container = this.$.visualization;

            const items = new vis.DataSet({
                type: {start: 'ISODate', end: 'ISODate'}
            });

            items.add([
                {id: 1, content: 'item 1<br>start', start: '2014-01-23'},
                {id: 2, content: 'item 2', start: '2014-01-18'},
                {id: 3, content: 'item 3', start: '2014-01-21'},
                {id: 4, content: 'item 4', start: '2014-01-19', end: '2014-01-24'},
                {id: 5, content: 'item 5', start: '2014-01-28', type: 'point'},
                {id: 6, content: 'item 6', start: '2014-01-26'}
            ]);

            const options = {
                width: '500px',
                height: '300px',
            };

            this.timeline = new vis.Timeline(container, items, options);

        }
    });
</script>

当我尝试使用它时。

<legacy-element></legacy-element>

它给了我以下错误。

Something is wrong with the Timeline scale. Limited drawing of grid lines to 1000 lines.

我已经尝试了vis's github issues中提供的所有解决方案

但是,没有成功!需要帮助。

【问题讨论】:

    标签: javascript polymer polymer-2.x vis.js polymer-starter-kit


    【解决方案1】:

    您需要将用于加载外部样式表的链接放在&lt;template&gt; 中。

    <dom-module id="legacy-element">
    
      <template>
    
        <link href="http://visjs.org/dist/vis.css" rel="stylesheet" type="text/css">
    
        <div id="visualization" style="height: 100%;width: 100%;border: 1px solid black"></div>
      </template>
    
      <script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.0/vis.js"></script>
    
      <script>
        // register an element
        MyElement = Polymer({
    
          is: 'legacy-element',
    
          ready: function() {
            const container = this.$.visualization;
    
            const items = new vis.DataSet({
              type: {
                start: 'ISODate',
                end: 'ISODate'
              }
            });
    
            items.add([{
              id: 1,
              content: 'item 1<br>start',
              start: '2014-01-23'
            }, {
              id: 2,
              content: 'item 2',
              start: '2014-01-18'
            }, {
              id: 3,
              content: 'item 3',
              start: '2014-01-21'
            }, {
              id: 4,
              content: 'item 4',
              start: '2014-01-19',
              end: '2014-01-24'
            }, {
              id: 5,
              content: 'item 5',
              start: '2014-01-28',
              type: 'point'
            }, {
              id: 6,
              content: 'item 6',
              start: '2014-01-26'
            }]);
    
            const options = {
              width: '500px',
              height: '300px',
            };
    
            this.timeline = new vis.Timeline(container, items, options);
    
          }
        });
      </script>
    </dom-module>
    

    注意:现在不推荐使用加载外部样式表,而支持 style modules。它仍然受支持,但支持将在 未来。

    或者,你可以这样做:

    &lt;link rel="import" type="css" href="http://visjs.org/dist/vis.css"&gt;

    而不是

    &lt;link href="http://visjs.org/dist/vis.css" rel="stylesheet" type="text/css"&gt;

    &lt;template&gt;之外。

    Demo

    【讨论】:

      猜你喜欢
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 2014-04-01
      • 2023-03-05
      • 1970-01-01
      • 2017-01-08
      相关资源
      最近更新 更多