简体   繁体   English

我无法使用jqplot正确绘制线图

[英]I can't get my line graph to plot correctly using jqplot

I want to plot a graph with the following as the xaxis: 我想绘制一个带有以下作为xaxis的图形:

var xaxis = [31.1,31.2,31.3,31.4,31.5, 32.1,32.2,32.3,32.4,32.5];

notice how there is a skip between 31.5 and 32.1. 注意在31.5和32.1之间如何跳过。 However, when I plot my line graph, there is a large space between these two points. 但是,当我绘制折线图时,这两点之间有很大的空间。 Here's my code: 这是我的代码:

 $(document).ready(function(){

                var cust1 = [[31.1,10],[31.2,15],[31.3,25],[31.4, 60],[31.5,95]];
                var cust2 = [[31.1,0],[31.2,15],[31.3,30],[31.4, 50],[31.5,85]];

                var data = [];
                data.push(cust1);
                data.push(cust2);

                var xaxis = [31.1,31.2,31.3,31.4,31.5, 32.1,32.2,32.3,32.4,32.5];

                var plot3 = $.jqplot('line-chart', data, 
                  { 
                      title:'Design Progress', 

                      axes: {
                          xaxis: {
                              //renderer: $.jqplot.LineRenderer,
                              label: 'Work Weeks',

                              ticks: xaxis
                          },
                          yaxis: {
                              label: "Percent Complete",
                              max: 100,
                              min: 0
                          }
                      }
                  }
                );

            });

I think it's because I'm not specifying a renderer option in my xaxis options. 我认为这是因为我没有在xaxis选项中指定渲染器选项。 However, I've tried to use $.jqplot.LineRenderer and $.jqplot.CategoryAxisRenderer without any luck (I even set my xaxis values as strings but that didn't work). 但是,我尝试使用$ .jqplot.LineRenderer和$ .jqplot.CategoryAxisRenderer却没有任何运气(我什至将xaxis值设置为字符串,但这也不起作用)。 Anybody know what's going on? 有人知道发生了什么吗?

Here's a pic to further clarify: 这是进一步澄清的图片:

在此处输入图片说明

Reason why it happens : jQuery flot library is building the graph with values that determined by your data. 发生这种情况的原因:jQuery flot库正在使用由您的数据确定的值来构建图形。

When you provide such data, the plugin will set the axis values to be as same as the text and with the borders of the numbers you gave. 当您提供此类数据时,插件会将轴值设置为与文本相同,并带有您输入的数字的边框。 what you can do, is set the text to be different than the axis value. 您可以做的是将文本设置为与轴值不同。

You can easily do it by options.xaxis.ticks.push([value, "the text"]) . 您可以通过options.xaxis.ticks.push([value, "the text"])轻松地做到这一点。

Pay attention that you are the one who is going to set which label will have which axis value, and this calls for setting the options parameter before calling the $plot 请注意,您将要设置哪个标签将具有哪个轴值,这需要在调用$plot之前设置options参数。

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

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