首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jqPlot - bart图表不生成

jqPlot - bart图表不生成
EN

Stack Overflow用户
提问于 2016-10-03 11:58:39
回答 1查看 44关注 0票数 1

我得到了喜欢的价值,但无法生成图表。下面是我的条形图的javascript代码。

代码语言:javascript
复制
$(document).ready(function(){
        $.jqplot.config.enablePlugins = true;

        var s1=${likes};
        var s2=[30000000];
        var s3 =[42000000];

      var z=[s1,s2,s3];
         var ticks = ['Your Organisation','Competitor#1','Cometitor#2'];
        plot1 = $.jqplot('chart1', [z], {
            // Only animate if we're not using excanvas (not in IE 7 or IE 8)..
            animate: !$.jqplot.use_excanvas,
            seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                pointLabels: { show: true }
            },
           axes: {
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer,
                    ticks: ticks
                },
                 yaxis: {
                                        min:0,
                                        max:10000000000,
                     tickOptions: {formatString: '%d'},
                    ticks:[0,10000000,20000000,30000000,40000000,50000000]
                                    }
            }, 
            highlighter: { show: false }
        });

     $('#chart1').bind('jqplotDataClick', 
            function (ev, seriesIndex, pointIndex, data) {
                $('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
            }
        );
        }); 

当我直接通过变量z数组传递变量时,就会生成图表,并且只在第一次勾选时生成图表。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-17 10:27:15

试试下面的代码。因为您呈现的是一个列表,所以在var s1中,您将得到一个值列表。你必须先取第一值。

代码语言:javascript
复制
$(document).ready(function() {
    $.jqplot.config.enablePlugins = true;

    var s1 = ${likes[0]}; //first vaue from the list
    var s2 = [30000000];
    var s3 = [42000000];

    var z = [s1,s2,s3];
    var ticks = ['Your Organisation', 'Competitor#1', 'Cometitor#2'];
    plot1 = $.jqplot('chart1', [z], {
        // Only animate if we're not using excanvas (not in IE 7 or IE 8)..
        animate: !$.jqplot.use_excanvas,
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            pointLabels: { show: true }
        },
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            },
            yaxis: {
                min:0,
                max:10000000000,
                tickOptions: {formatString: '%d'},
                ticks:[0,10000000,20000000,30000000,40000000,50000000]
            }
        }, 
        highlighter: { show: false }
    });

    $('#chart1').bind('jqplotDataClick', 
            function (ev, seriesIndex, pointIndex, data) {
                $('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
            });
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39831054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档