SW4*_*SW4 5 javascript raphael
我最近开始使用gRaphael来满足我的图形需求,到目前为止我印象非常深刻.但是,在生成折线图时遇到了一些困难,特别是当我尝试将X轴的值设置为日期时,图形无法渲染.我生成图表的代码是:
<script type='text/javascript' charset='utf-8'>
var r = Raphael('holder');
var lines = r.g.linechart(20, 20, 600, 300, [[1, 2, 3, 4, 5, 6, 7]], [['4.16','6.35','1.77','3.1','9.79','10.03','-0.3']], {nostroke: false, axis: '0 0 1 1', symbol: 'o', smooth: false}).hoverColumn(function () {
this.tags = r.set();
for (var i = 0, ii = this.y.length; i < ii; i++) {
this.tags.push(r.g.tag(this.x, this.y[i], this.values[i], 160, 10).insertBefore(this).attr([{fill: '#fff'}, {fill: this.symbols[i].attr('fill')}]));
}
}, function () {
this.tags && this.tags.remove();
});
lines.symbols.attr({r: 3});
</script>
<div id='holder'></div>
Run Code Online (Sandbox Code Playgroud)
我怎么能用'2001年1月,2001年2月,2001年3月......等等......取代X轴值'1,2,3,4,5,6,7'...... "?
非常感谢,所有人都非常感谢!
小智 7
首先,你必须给图表一些它不会抱怨的值.在您的情况下,您可以保存UNIX时间戳等然后您可以使用类似的东西更改值(使用原型等):
lines.axis[0].text.items.each( function ( index, label ) {
//Get the timestamp you saved
originalText = label.attr('text');
newText = 'CONVERT TIMESTAMP TO DATE USING originalText as input HERE';
//label.rotate(75);
label.attr({'text': newText});
});
Run Code Online (Sandbox Code Playgroud)
.each可以被常规替换
for(var x = 0; x < lines.axis[0].text.length; x++)
Run Code Online (Sandbox Code Playgroud)
循环,如果你喜欢.
归档时间: |
|
查看次数: |
3569 次 |
最近记录: |