简体   繁体   English

为什么我的jqPlot没有渲染画布?

[英]Why is my jqPlot not rendering a canvas?

I am trying to use jqPlot for a bar graph and I can't get it to show anything. 我正在尝试使用jqPlot作为条形图,我无法让它显示任何内容。

I have included the jqPlot code and all the plugins. 我已经包含了jqPlot代码和所有插件。 I am not receiving any errors whatsoever 我没有收到任何错误

I have copied the example code directly: 我直接复制了示例代码:

html: HTML:

<div id="jqplot" class="plot">

</div>

Javascript: 使用Javascript:

"use strict";
(function ($){

        $.jqplot('jqplot',  [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);

})(jQuery);

It is adding the class 'jqplot-target' to the 'jqplot' div so the javascript must be working, yet it is not adding a canvas/chart to the div, it displays just an empty div with the added class to it. 它将类'jqplot-target'添加到'jqplot'div中,因此javascript必须正常工作,但它没有向div添加画布/图表,它只显示一个带有添加类的空div。

Any ideas why this is not rendering? 任何想法为什么这不渲染?

I am using html5boilerplate as well, but I can't find any known issues with the two of them. 我也在使用html5boilerplate,但我找不到其中两个已知问题。

Thanks, 谢谢,

Thomas 托马斯

I found the problem. 我发现了这个问题。 I had the main container div that the jqplot is inside set to display:none on page load and once you click the 'enter' button is shows with .fadeIn() 我有一个主容器div,jqplot在里面设置显示:在页面加载时没有,一旦你点击'enter'按钮显示.fadeIn()

I suppose it can't add the canvas when the parent is display: none; 我认为当父显示时它无法添加画布:none; - I've got it to work by calling the $.jqplot inside the function that fades in the main container after the user clicks enter... - 我通过在用户单击enter之后调用主容器中淡入的函数内的$ .jqplot来实现它...

Can you show what your CSS is doing to the class "plot"? 你能展示你的CSS对课堂“剧情”的影响吗? The jqPlot Usage page says that you need to be sure to add width and height to the plot target. jqPlot Usage页面表示您需要确保为绘图目标添加宽度和高度。

Use the replot function on the generated chart, when you click on your button. 单击按钮时,在生成的图表上使用replot功能。

// create your chart
var plot1 = $.jqplot(...);

// hook the button press
$("button#enter").on("click", function(){
    // fade your tab in, wait for it to complete,
    $(".tab").fadeIn(1000, function(){
        // then replot, if not already drawn
        if(!plot1._drawCount){
            plot1.replot();
        }
    });
});

http://www.jqplot.com/deploy/dist/examples/hiddenPlotsInTabs.html http://www.jqplot.com/deploy/dist/examples/hiddenPlotsInTabs.html

I ran into this issue earlier, for some reason the following jqplot code wouldn't work: 我之前遇到过这个问题,由于某种原因,以下jqplot代码不起作用:

$(document).ready(function () {
    $.jqplot('chart1', [[[1, 2], [3, 5.12], [5, 13.1], [7, 33.6], [9, 85.9], [11, 219.9]]]);
}

However, when I switched the $(document).ready(function{...} to jQuery(function ($){..} the jqplot code worked properly. 但是,当我将$(document).ready(function {...}切换到jQuery(function($){..}时,jqplot代码正常工作。

jQuery(function ($) {
    $.jqplot('chart1', [[[1, 2], [3, 5.12], [5, 13.1], [7, 33.6], [9, 85.9], [11, 219.9]]]);
}

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

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