- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 d3.js 的新手,我正在尝试用针制作一个仪表。
var margin = { top: 0, left: 0, right: 0, bottom: 0 },
width = 800,
height = 600;
var maxVal = 12;
var svg = d3.select(".container").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var bgArc = d3.svg.arc()
.outerRadius(100)
.innerRadius(10)
.startAngle(0)
.endAngle(2 * Math.PI);
var needleScale = d3.scale.linear().domain([0, 360]).range([0, 180]);
//draw donut
var wrap = svg.append("g")
.attr("class", "wrap")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
wrap.append('g')
.attr('class', 'donut')
.append("path")
.attr("d", bgArc)
.style("fill", "white")
.style("stroke-width", 2)
.style("stroke", "white");
wrap.append('g')
.attr('class', 'outerMostCircle')
.append("circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 108)
.style("stroke", "white")
.style("stroke-width", 2)
.style("fill", "transparent");
//draw needle
var needle = wrap.append('g')
.attr("class", "needle")
.append("line")
.attr("x1", 0)
.attr("y1", 0)
.attr("x2", 0)
.attr("y2", -102)
.attr("stroke-width", 6)
.attr("stroke", "coral");
// add text
var text = svg.append("g")
.attr("class", "text")
.append("text")
.attr("transform", "translate(" + width / 2.2 + "," + height / 4 + ")")
.attr("font-size", "2em");
setInterval(function() {
curVal = Math.floor(Math.random()* 12);
d3.select('.needle').select('line')
.transition()
.duration(1000)
.attrTween('transform', function() {
return tweenNeedle(curVal, maxVal);
});
text.datum(curVal).text(function(d) {
return d + " m/s";
});
}, 1500);
function tweenNeedle(data, max) {
return d3.interpolateString("rotate(0)", "rotate(" + (data / max * 360) + ")");
}
function getEndAngle(data, max) {
return data / max * 2 * Math.PI;
}
wrap.append('g')
.attr('class', 'outerCircle')
.append("circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 20)
.attr("fill", "pink");
wrap.append('g')
.attr('class', 'innerCircle')
.append("circle")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", 10)
.attr("fill", "#666");
问题是,每当数据发生变化时,指针总是从开始位置而不是最后位置旋转。
我试图记住针的最后位置/Angular ,但我似乎无法记住......
我应该怎么做才能解决这个问题?
这是我到目前为止所做的事情。 https://jsfiddle.net/pq7t2obc/8/提前致谢!
最佳答案
正如 @Robert 的评论所述。这是 js fiddle 。
只需存储旧的旋转并使用它来补间到新的计算位置,如下所示。
// Define global variable
var lastRotationAngle = "rotate(0)";
// Calculate new tween and return InterpolateString into variable.
// inside .attrTween('transform', function() {
var interpolateString = tweenNeedle(lastRotationAngle, curVal, maxVal);
// Update lastRotationAngle
lastRotationAngle = "rotate(" + (curVal / maxVal * 360) + ")";
// Return the InterpolateString
return interpolateString;
https://jsfiddle.net/pq7t2obc/8/
补间针功能新:
function tweenNeedle( oldRotation, data, max) {
return d3.interpolateString(oldRotation, "rotate(" + (data / max * 360) + ")");
}
关于javascript - d3.js 仪表针随动态数据旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38585575/
我是 ASM(字节码操作工具包)的新手,正在使用它来检测 Java 字节码。我想访问类的方法并使用 ASM 更改它们的访问修饰符。有人知道如何实现这一目标吗?我知道调用 visitMethod 会有所
如何使用 Instrumentation 从 TestCase 中控制 Android Activity 的生命周期? 关于 official documentation ,声明为“生命周期控制:使用
我正在尝试构建类似于以下内容的 SVG: 笔画是完全动态的,因为它们来自 API。我想将笔画放在收到的点上(作为百分比值数组)。不必有序且两笔之间的距离不必相等 我正在尝试类似下面的方法,但无法提出笔
我正在使用基于 (Chartjs-tsgauge) 的仪表图表。 我想为图表设置与仪表限制分开的背景颜色。如何的问题图表.JS 渲染背景,因为我使用的插件没有关于背景的代码。 例如,我有一个有限制的仪
我有一个来自 logstash 的数据,它显示了数据库中的表使用了多少空间以及表的最大分配容量。我想在 Kibana 中为每个表创建显示当前占用多少空间的仪表。 问题是最大可用空间有时会发生变化,因此
我正在使用 HighChart 的 Angular Gauge,想知道是否可以有不等的间隔。目前,Y 轴上的不等间隔会影响仪表中每个绘图带的大小。如何才能在 Y 轴上具有相等的绘图带大小和不等间隔。
我是 HighCharts 的新手。 我有一个问题,当页面上有多个仪表时,第一个仪表会消失。 这个例子工作正常: HighChart test
我正在尝试使用一些现成的 javascript 来制作仪表。我快到了,但我不知道如何管理值(value)标题。 现在我的代码是这样工作的: 这就是我喜欢它的工作方式: 不知道如何解决问题。使用 Mat
我需要创建一个如下图所示的仪表。 我尝试使用JustGage为了做到这一点,但我找不到渲染仪表下部的方法(图像中的红色半圆)。 我想使用 JustGage。有人知道如何使用 JustGage 绘制“镜
我正在尝试在页面上插入多个 Google 仪表(或 Highchart 仪表)实例。 我想使用不同的选项集并将它们分开。所以我不能使用这里介绍的解决方案,我认为:Google Charts multi
我正在创建一个单页仪表板,它将在我想显示一些图表的监视器上全屏运行。我已经制作了图表,现在我只需要一个合适的页面模板。我在想这样的事情 我真的很喜欢它的外观,但我对如何使用大概的 css/js 制作这
我正在尝试编写一个应用程序,它从加速度计中获取值并通过条形仪表(或者可能是针规)显示它们,但我不确定如何让仪表工作。我正在考虑这些选择: 将仪表分成多个部分,因此仪表“填满”的多个图像,并根据加速度计
我正在尝试使用 Modbus 协议(protocol)对 Socomec 仪表执行 ping 操作,经过研究,我发现了 NModbus,这是一个 C# 库。我之前从未使用过库或 C#(通常是 Java
是否可以将 flexdashboard(下图)中的仪表嵌入 Shiny 应用程序(shinydashboard 或 shiny) >)? 来自 flexdashboard 的 Shiny flexda
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我尝试向我的网站添加仪表,我将 js 和 css 添加到我的信息文件 比在页面中我有这段代码 $(document).ready(function(){ s1 = [1]; plo
我正在尝试在数据标签中添加图标,我成功地添加了一些像这样的 HTML return 'Partially rejected: ' + partial + '' +'Rejected: ' + reje
我发现了一些像 VU 表一样移动指针的 CSS。这模仿了我想做的事情。然而,它从头到尾做一个完整的动画。而我想通过一系列的点击来实现改变。我试图弄清楚如何做到这一点,但我没有成功。我想知道如何让针只通
我在 D3 或 C3js 中寻找这样的东西: C3 中的默认 Gauge Chart 将多个列作为数据,但随后将它们显示在同一行上,因此它们相互覆盖。 最佳答案 如果您使用的是 Angular 4,则
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我是一名优秀的程序员,十分优秀!