2014-02-28 58 views
0

我想创建一个图表,其中x轴中的值是字符串而不是整数。 目前我有什么看起来像这样:x轴中的字符串

10 | 
    8 | 
    4 | 
    0 |__________ 
     1 3 5 

,我想让它像这样:

10 | 
    8 | 
    4 | 
    0 |____________________________ 
     January February March 

我使用NVD3图表。任何帮助,将不胜感激。

我会传递数据,但目前我手动。

function profiles() { 
    var profiles = []; 

    profiles.push({x:1,y:5}); 
    profiles.push({x:2,y:3}); 
    profiles.push({x:3,y:9}); 
    profiles.push({x:4,y:6}); 
    profiles.push({x:5,y:6}); 
    profiles.push({x:6,y:8}); 
    profiles.push({x:7,y:4}); 
    profiles.push({x:8,y:7}); 
    profiles.push({x:9,y:5}); 
    profiles.push({x:10,y:8}); 
    profiles.push({x:11,y:6}); 
    profiles.push({x:12,y:12}); 


    return [{ 
     values: profiles, 
     key: "Profiles", 
     color: "#ff7f0e" 
    }]; 
} 

而不是x:1我想x:1月例如。

+0

你在数据中传递日期吗?你可以在问题中发布你的代码片段吗? – shabeer90

+0

这个例子可能有助于http://nvd3.org/ghpages/discreteBar.html – Adween

回答

0

我会根据您的指导来访问此页http://nvd3.org/ghpages/discreteBar.html。这似乎允许您在传入的数组中创建标签和值。如果数字来自其他地方,则可以创建一个月份名称数组,然后使用月份值-1来访问它们(1月为0数组是从零开始的),所以......

var months=["January","February","March","April","May","June","July","August","September","October","November","December"]; 

然后

profiles.push({"label": months[0] , "value":5 }); // jan 
profiles.push({"label": months[1] , "value":3 }); // feb 
etc... 

我想这应该指向你在正确的方向,并得到图表,显示的字符串。