- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的 plnkr .
目前我的 NVD3 图表是基于他们的 linePlusBarChart .
问题是,在我的真实应用程序中,我实际上有更多的条形刻度数据 (4000+),因此条形变得超细并且很难看到,因此我需要改为使用线面积图。 (这在我的 plnkr 示例中并不明显,因为它为条形图使用了一个小的假样本大小。)
有没有其他人尝试过这样做?将条形图变成线面积图?
代码:
var data = [{
"key": "Price",
"color": "#4C73FF",
"values": [
[1443621600000, 71.89],
[1443619800000, 75.51],
[1443618000000, 68.49],
[1443616200000, 62.72],
[1443612600000, 70.39],
[1443610800000, 59.77]
]
}, {
"key": "Quantity",
"bar": true,
"values": [
[1136005200000, 1],
[1138683600000, 2],
[1141102800000, 1],
[1143781200000, 0],
[1146369600000, 1],
[1149048000000, 0]
]
}];
nv.addGraph(function() {
var chart = nv.models.linePlusBarChart()
.margin({
top: 20,
right: 40,
bottom: 50,
left: 40
})
.x(function(d, i) {
return i
})
.y(function(d) {
return d[1]
})
.color(d3.scale.category10().range());
chart.xAxis.tickFormat(function(d) {
var dx = data[0].values[d] && data[0].values[d][0] || 0;
// return time in hours:
return d3.time.format('%I:%M')(new Date(dx));
});
chart.y1Axis
.tickFormat(d3.format(',f'));
chart.y2Axis
.tickFormat(function(d) {
return '$' + d3.format(',f')(d)
});
chart.bars.forceY([0]);
chart.lines.interactive(false);
chart.height(300);
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart);
chart.update();
nv.utils.windowResize(chart.update);
return chart;
});
最佳答案
开箱即用,NVD3 为您提供 multiChart ( example ),它结合了折线图/条形图/面积图。注意:
最后,这是一个使用示例数据的简单多图表 (NVD3 1.8.1),左侧是数量(面积),右侧是价格(线):
var data = [{
"key": "Price",
"type": "line",
"yAxis": 2,
"values": [
[1443621600000, 71.89],
[1443619800000, 75.51],
[1443618000000, 68.49],
[1443616200000, 62.72],
[1443612600000, 70.39],
[1443610800000, 59.77],
]
}, {
"key": "Quantity",
"type": "area",
"yAxis": 1,
"values": [
[1136005200000, 1],
[1138683600000, 2],
[1141102800000, 1],
[1143781200000, 0],
[1146369600000, 1],
[1149048000000, 0],
]
}];
data = data.map(function(series) {
series.values = series.values.map(function(d) {
return {
x: d[0],
y: d[1]
}
});
return series;
});
nv.addGraph(function() {
var chart = nv.models.multiChart()
.margin({
top: 20,
right: 40,
bottom: 50,
left: 40
})
.yDomain1([0, 10])
.yDomain2([0, 100]) // hard-coded :<
.interpolate("linear") // don't smooth out the lines
.color(d3.scale.category10().range());
chart.xAxis.tickFormat(function(d) {
return d3.time.format('%I:%M')(new Date(d));
});
chart.yAxis1.tickFormat(d3.format(',f'));
chart.yAxis2.tickFormat(function(d) {
return '$' + d3.format(',f')(d)
});
chart.lines2.interactive(false); // line chart, right axis
d3.select('svg#chart')
.datum(data)
.transition().duration(500).call(chart);
chart.update();
nv.utils.windowResize(chart.update);
return chart;
});
text {
font: 12px sans-serif;
}
svg {
display: block;
}
html,
body,
svg#chart {
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.min.css" rel="stylesheet" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.2/d3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.min.js"></script>
<svg id="chart"></svg>
关于javascript - 如何将NVD3条形图转换成面积折线图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32914186/
我正在开发一个企业名录网站,其搜索将由 Google map 驱动。用户将能够根据各种标准搜索他们所在地区的企业,但主要的想法是,如果您搜索例如“新泽西州的水管工”,您将获得新泽西州所有水管工的结果。
我得到了一条任意形状的曲线,包围了一些区域。 我想估计曲线在 iPhone/iPad 屏幕上包围的像素数。我该怎么做? 曲线被定义为点的连续 x/y 坐标。 闭合曲线。 通过用户的触摸(touches
我想删除 R 在点阵图周围的默认边距。这意味着我想摆脱红色矩形之外的所有空白。这是示例: library (raster) library(rasterVis) f <- system.file("e
无法找到任何直接的解决方案来计算 GMSPolygon 对象面积。有什么方法可以做到这一点,或者我必须用边长和一些数学计算来计算它? 最佳答案 感谢@Larme; GMSGeometryArea 就是
假设例如我想将标准正态分布的密度曲线下方的面积着色为十分。我希望最左边 10% 的区域具有与接下来的 10% 不同的阴影,依此类推。 这是问题“Shading a kernel density plo
我正在为 Extjs 开发一个混合图表组件,并且曲线太尖锐了。我找不到曲线具有半径的配置。如果你处理过类似的事情,你能提供一些方法让我的曲线变得平滑一点吗?这是我的代码: Ext.define('Ex
上下文 我有一个 3D 对象,我有它的坐标。然后我将对象旋转 n 次,当对象投影到网格上时,我想计算对象的 2D 面积(以纳米为单位)。 例如, 我在下面有一张图片描述了我的问题。我有相同的对象,但在
当我知道我需要的地 block 总数并且我希望排列是一个正方形(可能有一些空的子地 block )时,我正在尝试弄清楚如何计算子地 block 尺寸。 例如,如果我需要 22 个子图,那么我会为总共
我是一名数据科学家。主要使用Python和SQL来编写代码。我使用data studio进行可视化。所以我对JS不熟悉。我的诀窍data studio community visualizations
我有 1797 张 Mnist 图像,为此我需要提取两个特征(FilledArea、EulerNumber)。我知道如何在 Matlab 中做到这一点。我的特征矩阵在 Matlab 中具有(并且是正确
我希望能够在 Google map 上绘制形状(圆形、多边形和矩形),但我想限制可以绘制的形状的大小(面积)。因此,以圆圈为例,期望的行为是当用户开始从 map 上的某个点拖动鼠标以形成圆圈时,圆圈会
我是一名优秀的程序员,十分优秀!