doc

http://nvd3-community.github.io/nvd3/examples/documentation.html

https://github.com/mbostock/d3/wiki

http://pkuwwt.gitcafe.io/d3-tutorial-cn/about.html

example

http://nvd3.org/livecode/index.html

unix timestamp不能格式化?

apparently, d3 uses 13 digits unix timestamp (including microseconds) and you have 10 digits unix timestamp. try doing this:

.tickFormat(function(d) { return d3.time.format('%x')(new Date(d*1000)) });

效果图

{% extends "base.html" %}

{% block title %}graph{% endblock %}

{% block head %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/nv.d3.css') }}">
<script src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/nv.d3.min.js') }}"></script>
{% endblock %} {% block body %}
<div class="uk-grid" style="margin:10px;"> {% for service in services %}
<div class="uk-width-1-3">
<strong>{{ service }}</strong>
</div> <div class="uk-width-2-3">
<ul class="uk-tab" data-uk-tab>
<li class="uk-active" id="{{ service }}-hour"><a href="#">Hour</a></li>
<li id="{{ service }}-day"><a href="#">Day</a></li>
<li id="{{ service }}-week"><a href="#">Week</a></li>
<li id="{{ service }}-month"><a href="#">Month</a></li>
<li id="{{ service }}-year"><a href="#">Year</a></li>
</ul>
<svg id="{{ service }}" style='height:250px'/>
</div>
{% endfor %} </div> <script type="text/javascript">
$(function() {
$("svg").each(function(idx, data) {
var hostname = "{{ hostname }}";
var service = $(this).attr('id');
draw_graph(hostname, service, '-1h', '%H:%M');
}); $("li[id$=hour]").bind("click", function(){
var hostname = "{{ hostname }}";
var service = $(this).attr('id').split('-')[0];
draw_graph(hostname, service, '-1h', '%H:%M');
}); $("li[id$=day]").bind("click", function(){
var hostname = "{{ hostname }}";
var service = $(this).attr('id').split('-')[0];
draw_graph(hostname, service, '-1d', '%H:%M');
}); $("li[id$=week]").bind("click", function(){
var hostname = "{{ hostname }}";
var service = $(this).attr('id').split('-')[0];
draw_graph(hostname, service, '-1w', '%b %d');
}); $("li[id$=month]").bind("click", function(){
var hostname = "{{ hostname }}";
var service = $(this).attr('id').split('-')[0];
draw_graph(hostname, service, '-1m', '%b %d');
}); $("li[id$=year]").bind("click", function(){
var hostname = "{{ hostname }}";
var service = $(this).attr('id').split('-')[0];
draw_graph(hostname, service, '-1y', '%b %d');
}); function draw_graph(hostname, service, period, xformat) {
$.ajax({
type: 'GET',
url: "{{ url_for('api.rrd') }}",
data: { 'hostname': hostname, 'service': service, 'period': period },
dataType: 'json',
success: function(data){
nv.addGraph(function() {
var chart = nv.models.lineChart()
.useInteractiveGuideline(true)
//.showLegend(false)
//.color(d3.scale.category20c().range())
; /*chart.tooltip
.headerFormatter(function(d) { return d3.time.format('%x')(new Date(d)); })
.valueFormatter(function(d){ return d3.round(d, 3); })
;*/ chart.xAxis
//.axisLabel('Date')
.ticks(8)
.tickFormat(function(d) { return d3.time.format(xformat)(new Date(d)); })
.showMaxMin(false)
.rotateLabels(-30)
; chart.yAxis
//.axisLabel('Traffic')
.tickFormat(d3.format('.4s'))
//.tickFormat(function(d) { return d3.round(d, 3); })
.showMaxMin(false)
; chart.xScale(d3.time.scale())
; chart.yScale(d3.scale.linear())
; d3.select('#'+service)
.datum(data)
.transition()
.duration(0)
.call(chart)
; nv.utils.windowResize(function() { d3.select('#chart svg').call(chart) })
; return chart;
});
},
});
};
})
</script> {% endblock %}

最新文章

  1. HDOJ 2561. 第二小整数 第k大问题
  2. 2016-09-19: linux后台运行
  3. 将CachedRowSet中的数据转储到对象中
  4. iOS-GCD用法
  5. 关于java -version版本问题
  6. linux守护进程解读
  7. Codeforces 306B
  8. Hbase数据库安装
  9. 5.Redis常用命令:Hash
  10. 解析新浪微博表情包的一套js代码
  11. ES6.3.2 index操作源码流程
  12. 南邮攻防训练平台逆向maze
  13. windows操作系统python selenium webdriver安装
  14. 【Java每日一题】20170321
  15. spring batch批量处理框架
  16. SpringBoot集成监控管理
  17. P4890 Never&#183;island(dp)
  18. Mac上搭建nginx教程
  19. 关于easyUI异步获取数据格式问题
  20. dongle0

热门文章

  1. linux的理解
  2. angularJs实现修改功能
  3. Exadata LVM snapshot备份失败
  4. fatal error C1859: “Release\IWBServer.pch”意外的预编译头错误,只需重新运行编译器就可能修复此问题
  5. 2018-2019-2 20165320 《网络对抗技术》 Exp6 信息搜集与漏洞扫描
  6. Canvas 动态小球重叠效果
  7. Experimental Educational Round: VolBIT Formulas Blitz A
  8. UBoot添加命令的方法
  9. NPOI2.0导出excel之添加样式、边框和表头
  10. php数组&#183;的方法-数组与数据结构