1

我正在尝试使用 jQuery 图表插件 Flot 制作堆积条形图。

两个系列的数据都以 json 格式输入:[{"label":"Uncategorized","data":[[1309374000000,"3448876"],[1309377600000,"3352757"]...

这似乎与这里发生的问题相同,但没有发布任何回复。 http://groups.google.com/group/flot-graphs/browse_thread/thread/c6445ff7dce59ea0/e996979c40bc3f6b?show_docid=e996979c40bc3f6b

有人看到这个错误或知道我应该去哪里看吗?

超出最基本的堆叠示例的任何内容似乎都存在严重问题。

我试过扭转这个系列,但没有任何运气。所有数据都按日期排序,并且日期在系列之间对应。

http://rpbailey.net/flotError.PNG

编辑:我的浮动选项...正在创建两个图表,查看第二个(底部)一个。

                //get the date format
                strTimeFormat = "%y/%m/%d";
                if(strOb == 'Hour'){ strTimeFormat = "%y/%m/%d %H"; arrMinTick = [1, 'hour']; intBar = 1000000}
                if(strOb == 'Day'){ strTimeFormat = "%y/%m/%d"; arrMinTick = [1, 'day']; intBar =100000000}
                if(strOb == 'Month' | strOb == 'Quarter'){ strTimeFormat = "%y/%m"; arrMinTick = [1, 'month'];intBar = 3000000000}

                objOptions = {
                    colors:[ '#dddddd','#00ff00','#ffff00','#ff0000']
                    ,series:{points:{show:true},lines:{show:true},stack:0}
                    ,xaxis: { mode: "time", timeformat: strTimeFormat, minTickSize: arrMinTick }
                }           

                objOptions2 = {
                    series:{bars:{show:true, barWidth: intBar}, stack:-1000000}
                    ,xaxis: { mode: "time", timeformat: strTimeFormat }
                }   

                if(mode == 'percentage'){
                    objYaxes = {    yaxis:{
                         alignTicksWithAxis: 1
                        ,position: 'right'
                        ,tickFormatter: function(label, series){ return label +"%"; }
                    }};
                    //add on th yaxes options.
                    objOptions = jQuery.extend(objOptions, objYaxes);
                    objOptions2 = jQuery.extend(objOptions2, objYaxes);
                    console.log(objOptions);
                }

                 //top chart    
                jQuery.getJSON('includes/webRepFunctions.php', {chart:'risk',start:strStart,stop:strStop,ob:strOb,metric:mode}, function(data) {
                        jQuery.plot(jQuery("#flot1"),data,objOptions);                      
                    });

                 //bottom chart 
                jQuery.getJSON('includes/webRepFunctions.php', {chart:'cat',start:strStart,stop:strStop,ob:strOb,metric:mode}, function(data) {
                        jQuery.plot(jQuery("#flot2"),data,objOptions2);                     
                    });

                }

编辑2:更多示例数据...

[{"label":"Uncategorized","data":[[1309374000000,"3448876"],[1309377600000,"3352757"],[1309381200000,"2897092"],[1309384800000,"2747047"],[1309388400000,"2693610"],[1309392000000,"2511211"],......[1310097600000,"1404290"]],"yaxis":1},{"label":"Categorized","data":[[1309374000000,"1371941"],[1309377600000,"1273494"],[1309381200000,"1505119"],[1309384800000,"1463382"],[1309388400000,"1316429"],[1309392000000,"1201810"],......[1310097600000,"611780"]],"yaxis":1}]

4

2 回答 2

1

我有同样的问题,但参考了 jquery.flot.stack.js 和 jquery.flot.stack.min.js

一旦我删除了 min js ref,空白间隙问题就消失了......

于 2011-10-08T20:06:29.323 回答
1

您的两个系列是否具有相同数量的数据点?我无法从中看出,因为你已经留下了一些数据。这似乎是一个令人烦恼的问题,但如果您在每个系列中没有相同数量的[x,y]配对,这些图表就会表现得很奇怪。如果未定义,请使用null. [x,y]我正在考虑除了一个非常损坏的插件之外还有什么问题,因为我之前也绘制过类似的东西并且遇到了一些问题,但我无法再访问该代码了。

尝试objOptions2 = jQuery.extend(objOptions2, objYaxes); 从您的代码中删除。同样,这个插件并不是最好的,并且在 Flot 的某些属性方面存在问题。

也尝试barWidth: intBarobjOptions2.

尝试单独删除它们。

除此之外,尝试将有问题的图表单独放在页面上,除了相关的内容外,不要使用其他 HTML/CSS/Javascript。

于 2011-07-08T18:27:07.830 回答