首页 \ 问答 \ 在同一html页面中使用不同数据复制图表/图形(Duplicate charts/graphics with different data in the same html page)

在同一html页面中使用不同数据复制图表/图形(Duplicate charts/graphics with different data in the same html page)

这是在网页上显示图表的HTML:

<div class="chart" id="p1">
<canvas id="c1" width="560" height="260" style="width: 560px; height: 260px;"></canvas>
</div>

这就是生成图表的原因:

<script>
    var c1 = document.getElementById('c1');
    var parent = document.getElementById('p1');
    c1.width = parent.offsetWidth - 40;
    c1.height = parent.offsetHeight - 40;
    var data1 = {
        labels: [
            'Seg',
            'Ter',
            'Qua',
            'Qui',
            'Sex',
            'Sab',
            'Dom'
        ],
        datasets: [{
                fillColor: 'rgba(255,255,255,.1)',
                strokeColor: 'rgba(255,255,255,1)',
                pointColor: '#123',
                pointStrokeColor: 'rgba(255,255,255,1)',
                data: [
                    190,
                    200,
                    235,
                    390,
                    290,
                    250,
                    250
                ]
            }]
    };
    var options1 = {
        scaleFontColor: 'rgba(255,255,255,1)',
        scaleLineColor: 'rgba(255,255,255,1)',
        scaleGridLineColor: 'transparent',
        bezierCurve: false,
        scaleOverride: true,
        scaleSteps: 10,
        scaleStepWidth: 100,
        scaleStartValue: 0
    };
    new Chart(c1.getContext('2d')).Line(data1, options1);
        //@ sourceURL=pen.js
</script>

我想在同一网站页面中制作具有不同值的其他图表...我已经尝试复制代码并更改id =“c1”e id =“p1”但没有...


This is the HTML that display the chart on webpage:

<div class="chart" id="p1">
<canvas id="c1" width="560" height="260" style="width: 560px; height: 260px;"></canvas>
</div>

and this is the that generate the chart:

<script>
    var c1 = document.getElementById('c1');
    var parent = document.getElementById('p1');
    c1.width = parent.offsetWidth - 40;
    c1.height = parent.offsetHeight - 40;
    var data1 = {
        labels: [
            'Seg',
            'Ter',
            'Qua',
            'Qui',
            'Sex',
            'Sab',
            'Dom'
        ],
        datasets: [{
                fillColor: 'rgba(255,255,255,.1)',
                strokeColor: 'rgba(255,255,255,1)',
                pointColor: '#123',
                pointStrokeColor: 'rgba(255,255,255,1)',
                data: [
                    190,
                    200,
                    235,
                    390,
                    290,
                    250,
                    250
                ]
            }]
    };
    var options1 = {
        scaleFontColor: 'rgba(255,255,255,1)',
        scaleLineColor: 'rgba(255,255,255,1)',
        scaleGridLineColor: 'transparent',
        bezierCurve: false,
        scaleOverride: true,
        scaleSteps: 10,
        scaleStepWidth: 100,
        scaleStartValue: 0
    };
    new Chart(c1.getContext('2d')).Line(data1, options1);
        //@ sourceURL=pen.js
</script>

i want to make other charts with different values in the same website page... i already tried duplicate the codes and change id="c1" e id="p1" but nothing...


原文:https://stackoverflow.com/questions/29150278
更新时间:2023-07-29 16:07

最满意答案

有许多可能性可以避免这个问题:在评论中已经提到了延迟或撤消增量。 JVM有很多技巧,其中一些适用:

  • obj.doSomething(m_someVar)是非虚方法调用( privatefinal方法,或从不重写的方法)时,它可能需要显式空检查(*),因为没有SEGV,但NPE必须在通话前被抛出。 我假设该方法没有内联,否则应该在内联后应用此分析。
  • obj.doSomething(m_someVar)是一个虚方法调用时,你必须做“方法调度”,即像obj.getClass().getPointerToMethod("doSomething(int)") ,以确定具体方法是什么呼叫。 我写了“类似的东西”,因为这样做非常费时并且尽可能地进行优化。 如果obj恰好为null ,则此调度可以移动到增量之上,并且它本身将抛出NPE。
  • 如果你很幸运,那么调度可能看起来像if (obj.getClass() != MyClass.class) uncommon_trap(); ,这是最简单的情况(称为“单态调用站点”),但即使这涉及解除引用obj ,你再次得到一个NPE为null

(*)null检查可能看起来像obj.getClass() ,它在汇编程序中是从相对于obj指针的固定偏移量加载的单个指令。 当obj == null ,会触发未映射的页面。


There are many possibilities ho to avoid the problem: Delaying or undoing the increment was already mentioned in a comment. The JVM has a big bag of tricks and some of them applies:

  • When obj.doSomething(m_someVar) is a non-virtual method call (a private or final method, or a never overridden method), then it probably requires an explicit null check(*) as there would be no SEGV, but the NPE must be thrown before the call. I'm assuming the method was not inlined, as otherwise this analysis should be applied after inlining.
  • When obj.doSomething(m_someVar) is a virtual method call, then you have to do "method dispatch", i.e., something like obj.getClass().getPointerToMethod("doSomething(int)") in order to determine what concrete method to call. I wrote "something like" as doing this literally is very time-consuming and gets optimized away as much as possible. This dispatch can be moved above the increment and it itself will throw an NPE, if obj happens to be null.
  • When you're lucky, then the dispatch may look like if (obj.getClass() != MyClass.class) uncommon_trap();, which is the simplest case (called "monomorphic call site"), but even this involves dereferencing obj and you again get an NPE for null.

(*) A null check may look like obj.getClass() which in assembler is a single instruction loading from a fixed offset relative to the obj pointer. When obj == null then an unmapped page ist hit.

相关问答

更多
  • 布尔表达式的评估不应该被编译掉 - 至少通过javac。 即使Debug类文件当前对值没有任何作用,谁会说在执行时会出现这种情况? 在完成Debug类的编译后(通过使isAssertEnabled成为静态),javac仍然包含代码 - 但我期望JIT编译器将其删除(尽管您应该看到Peter引用的问题 )。 然后是否可以将该方法内容化为无,我不确定。 同样,如果JIT编译器可以做到这一点,并且如果它意识到评估参数不会有任何副作用,它可能会潜在地避免评估。 尽管如此,我不会亲自编写代码。 The evaluat ...
  • 我建议检查空值,而不是执行计算,而不是抛出异常。 一个例外应该是“特殊的”和罕见的,而不是一种管理控制流程的方式。 我还建议您与客户就输入参数建立合同。 如果允许空位拼出来, 如果它们不是,请清楚应该传递什么,默认值,以及如果传递空值,您承诺返回的内容。 I'd recommend checking for null and not doing the calculation rather than throwing an exception. An exception should be "excepti ...
  • 没有一个完整的答案,我根本没有时间做你的问题需要但希望有用的详细的基准。 了解你的敌人 您的目标是JVM(本质上是JIT)和底层CPU /内存子系统的组合。 因此,当您进入更积极的优化时,“所有这些在JVM X上更快”在所有情况下都不可能有效。 如果您的目标市场/应用程序将大部分运行在特定的架构上,那么您应该考虑投资具体的工具。 *如果您在x86上的表现是关键因素,那么英特尔的VTune非常适合您深入描述的jit输出分析 。 * 64位和32位JIT之间的差异可能是相当大的,特别是在x86平台上,调用约定可 ...
  • 没有理由这么做是不好的做法。 在您的示例中,您不清楚为什么要进行检查。 一个常见的例子可能是这样的 if (s == null || s.isEmpty()) // if s empty or not set. 要么 if (s != null && s.length() > 0) 通常,在需要时执行此操作,在这种情况下性能不重要。 通常你会写 if(x != null) 或更好 if (x == null) { // handle null, assuming this is not empt ...
  • 有许多可能性可以避免这个问题:在评论中已经提到了延迟或撤消增量。 JVM有很多技巧,其中一些适用: 当obj.doSomething(m_someVar)是非虚方法调用( private或final方法,或从不重写的方法)时,它可能需要显式空检查(*),因为没有SEGV,但NPE必须在通话前被抛出。 我假设该方法没有内联,否则应该在内联后应用此分析。 当obj.doSomething(m_someVar)是一个虚方法调用时,你必须做“方法调度”,即像obj.getClass().getPointerToMe ...
  • 是否有可能让thread2在NullPointerException检查后重写对象引用? 绝对地 - 它可以在play()方法执行时改变object的值,如果这就是你的意思。 这本身不会导致错误。 请注意,如果没有同步或其他内存障碍,thread2可能会更改object的值,而不会在不确定的时间段内注意到thread1。 很难说你应该做什么,没有任何关于代码更大目标的知识。 Is it possible to for thread2 to rewrite object reference after Nul ...
  • 怎么样: return (startDate == null || !date.before(startDate)) && (endDate == null || !date.after(endDate)); 这使用了这两个陈述是等同的事实: !(date.before(startDate) || date.after(endDate)) !date.before(startDate) && !date.after(endDate) 而事实是|| 是一个短路,它可以防止NullPointerEx ...
  • 编译器不能假定getResultCount()没有副作用 - 因此它不能删除该调用。 The compiler can't assume that getResultCount() has no side-effects -- therefore it can't remove the call.
  • 您看到的结果可能是由于首先运行“noFnCalls”,而没有在测试和测量之前引入适当的预热。 我明白了: withFnCalls ellapsed time: 444 noFnCalls ellapsed time: 471 withFnCalls ellapsed time: 334 noFnCalls ellapsed time: 331 withFnCalls ellapsed time: 330 noFnCalls ellapsed time: 325 withFnCalls ellapsed ti ...
  • 绝对不。 if (object)是原始boolean的实例,并且通过代理,包装类Boolean (自动拆箱), if (object)语法才会起作用。 另请注意, if (object)语法可用于较弱的类型化语言,如Groovy或JavaScript,并提供所有注意事项。 最后注意一个Boolean包装器在Java中也是可空的,因此if (object != null)语法实际上对于Boolean s也是有意义的(但不会为原始boolean s编译)。 Absolutely not. The if (obj ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。