如何获取Flot中的X轴标签以使用我的数据进行转换? [英] How can I get the X axis labels in Flot to be transformed with my data?

查看:98
本文介绍了如何获取Flot中的X轴标签以使用我的数据进行转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Flot 绘制一些从服务器中拉回的数据的图表.我收到的X轴数据以毫秒为单位,我想以X轴为单位以秒为单位显示图表.因此,我认为这是 API 轴选项.我这样应用了变换:

I am using Flot to chart some data that I pull back from the server. The X-axis data that I receive is in units of milliseconds, and I want to display the chart with the X-axis in units of seconds. So, I thought this was a good use of the API's transform axis option. I applied my transform like so:

var plot = $.plot($("#placeholder"),
       { 
         grid: { hoverable: true, clickable: true },
         xaxis: { transform: function(x) { return x/1000; } }
       });

我可以看到框架正在调用我的转换函数,并且可以看到这些点本身正在被转换-当我绑定plothover事件并将鼠标悬停在这些点上时,我可以看到X适当地转换值.问题在于,x轴刻度标签也没有转换.

I can see that my transform function is being called by the framework, and I can see that the points themselves are being transformed -- when I bind the plothover event and hover over the points, I can see that the X value is suitably transformed. The problem is that the x-axis tick labels are not also getting transformed.

我该怎么做才能使轴标签本身随数据转换?

What do I need to do to get the axis labels themselves transformed with my data?

推荐答案

我不确定正确"的答案是什么,但是您可以提供自己的刻度标签功能,只是让它执行与您相同的工作转换功能.

I'm not sure what the "right" answer is, but you can provide your own tick labelling function, and just have it perform the same job as your transform function.

var plot = $.plot($("#placeholder"),
   { 
     grid: { hoverable: true, clickable: true },
     xaxis: { transform: function(x) { return x/1000; },
              tickFormatter: function(x) { return x/1000; } }
   });

这篇关于如何获取Flot中的X轴标签以使用我的数据进行转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆