How can I get the X axis labels in Flot to be transformed with my data?

瘦欲@ 提交于 2020-01-05 17:36:48

问题


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; } }
       });

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?


回答1:


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; } }
   });


来源:https://stackoverflow.com/questions/2768348/how-can-i-get-the-x-axis-labels-in-flot-to-be-transformed-with-my-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!