将Google可视化折线图hAxis原点设置为其初始值
Set Google visualization line chart hAxis origin to its initial value
这是一个有粘性折线图的示例,其中图表绘制为
var Xmin = data.getValue(0, 0);
var options = {
title : 'Sample graph',
legend : {
position : 'bottom'
},
height : 400,
interpolateNulls : true,
'pointSize' : 5,
'vAxis' : {
title : "Count",
'minValue' : 0,
},
'hAxis' : {
title : "Month",
'minValue' : Xmin,
},
'animation' : {
'duration' : 1000,
'easing' : 'in'
},
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
如何将hAxis原点设置为Jan-13
而不是0
如果要将线条拉伸到图表的边缘,则需要为域轴使用连续数据类型(number
、date
、datetime
、timeofday
),而不是离散(string
)类型。由于您的数据是月份和年份,您可以使用date
类型:
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Month', 'Sales', 'Expenses'],
[new Date(2013, 0), 1000, 400],
[new Date(2013, 1), 1170, 460],
[new Date(2013, 2), 660, 1120],
[new Date(2013, 3), 1030, 540]
]);
// get the range of dates
var range = data.getColumnRange(0);
// pull back the start just a bit so the first axis label will show
range.min = new Date(range.min);
range.min.setMilliseconds(-1);
// format the dates
var dateFormatter = new google.visualization.DateFormat({pattern: 'MMM-yy'});
dateFormatter.format(data, 0);
var options = {
title : 'Sample graph',
legend : {
position : 'bottom'
},
height : 400,
interpolateNulls : true,
pointSize : 5,
vAxis : {
title : "Count",
minValue : 0,
},
hAxis : {
title : "Month",
format: 'MMM-yy',
viewWindow: {
min: range.min,
max: range.max
}
},
animation : {
duration : 1000,
easing : 'in'
},
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
google.load("visualization", "1", {packages:["corechart"], callback: drawChart});
参见示例:http://jsfiddle.net/asgallant/k3c9Q/
相关文章:
- 如何设置html元素填充的动画
- 需要帮助设置json数组
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 数组在递归方法中设置为null
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 在自定义 JS 游标上设置游标原点
- 即使在服务器将访问控制允许原点设置为“*”之后,也会收到javascript错误
- 如何在交叉原点的角度中设置xsrf令牌
- 设置变换原点特性的X和Y坐标
- YouTube iFrame API:设置原点中断视频事件+VEVO不't工作-2015年12月
- 根据原点和目标设置角度动画视图过渡
- 如何在javascript上设置img的交叉原点
- 正在设置访问控制允许原点
- Google Maps API v3 -设置目的地,但保留原点空白
- 将画布原点设置为左下角
- 如何在d3 JavaScript库中设置拖动行为的原点(drag. Origin)
- 设置画布缩放原点
- 如何在v4中在d3.js中拖动时设置原点
- 将Google可视化折线图hAxis原点设置为其初始值