简体   繁体   English

脚本功能在Chrome中运行一次,但在Firefox中可以正常运行

[英]Script function on running once in Chrome but works fine in Firefox

I am using NVD3 to make several graphs. 我正在使用NVD3制作多个图形。 I put a console.log in the addGraph function which adds a particular graph. 我在添加一个特定图形的addGraph函数中放置了console.log。

I am wondering whether there is something wrong in my code? 我想知道我的代码中是否有错误? Am I using the library correctly? 我是否正确使用图书馆? I do not know where to begin to resolve this issue. 我不知道从哪里开始解决此问题。

FIREFOX (All the graphs are displayed properly) FIREFOX (所有图形均正确显示)

total 444 Add graph is called here 共444个添加图在这里被调用

total 518 Add graph is called here 共有518条图在这里被调用

total 572 Add graph is called here 总计572添加图在这里被调用

total 553 Add graph is called here 共有553幅图在这里被调用

total 617 Add graph is called here 共有617个图在这里被调用

total 595 Add graph is called here 共有595幅图在这里被调用

GOOGLE CHROME 谷歌浏览器

total NaN 总NaN

total NaN 总NaN

total NaN 总NaN

total NaN 总NaN

total NaN 总NaN

Add graph is called here total 108 此处添加图的总数为108

total 138 总计138

total 145 总计145

total 146 总共146

CODE

Calling the scripts 调用脚本

<script src="../../../data/novus/lib/d3.v2.js"></script>
<script src="../../../data/novus/nv.d3.js"></script>
<script src="../../../data/novus/src/tooltip.js"></script>
<script src="../../../data/novus/src/models/legend.js"></script>
<script src="../../../data/novus/src/models/axis.js"></script>
<script src="../../../data/novus/src/models/scatter.js"></script>
<script src="../../../data/novus/src/models/line.js"></script>
<script src="../../../data/novus/src/models/multiChart.js"></script>

In the loop 在循环

<script src="../../../data/novus/nv.d3.js"></script>
<script>
    var impressions = [];
    var clickrate = [];
    var trial_impressions = [];
    var trial_clickrate = [];
    var testdata = [{
        "key" : "Impressions",
        "type" : "line",
        "values" : impressions,
        "yAxis" : 1
    }, {
        "key" : "Clicks",
        "type" : "line",
        "values" : clickrate,
        "yAxis" : 2
    }, {
        "key" : "T Impressions",
        "type" : "line",
        "values" : trial_impressions,
        "yAxis" : 1
    }, {
        "key" : "T Clicks",
        "type" : "line",
        "values" : trial_clickrate,
        "yAxis" : 2
    }].map(function(series) {
        series.values = series.values.map(function(d) {
            return {
                x : d[0],
                y : d[1]
            }
        });
        return series;
    });
    var chart;

    nv.addGraph(function() {
        console.log("Add");
        chart = nv.models.multiChart().margin({
            top : 30,
            right : 60,
            bottom : 50,
            left : 70
        }).x(function(d, i) {
            return i
        }).color(d3.scale.category10().range());

        chart.xAxis.tickFormat(function(d) {
            var dx = testdata[0].values[d] && testdata[0].values[d].x || 0;
            if ( typeof (dx) == undefined || d > 1000) {
                dx = new Date(d);
            } else {
                dx = new Date(dx);
            }
            return dx ? d3.time.format('%x')(dx) : '';
        });

        chart.yAxis1.tickFormat(d3.format(',.1f'));
        v

        chart.yAxis2.tickFormat(d3.format(',.4f'));

        d3.select('#chart1<?= $chartID?> svg').datum(testdata).transition().duration(500).call(chart);
        return chart;
    });

</script>

The div where the graph is called 图被调用的div

<div id='chart1<?= $chartID?>' style="width:1110px;height:300px;font-size:11px;margin-top:5px">
    <svg></svg>
</div>

My best guess is that there is mathematical calculations on those numbers. 我最好的猜测是对这些数字进行数学计算。 In witch case using the function parseFloat() can convert the string to a number so that mathematical calculations will be done correctly. 在女巫的情况下,使用函数parseFloat()可以将字符串转换为数字,以便正确进行数学计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM