- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 dynamic chart in canvasjs 。如果数据点高于某个定义值,图表就会发生变化。我想知道您是否可以回到过去,以便可以滚动浏览动态图表。
亲切的问候,肯
最佳答案
您可以将 Jquery Slider 与 viewport 一起使用为了达成这个。这是两个例子
http://jsfiddle.net/canvasjs/ydu922wL/
http://jsfiddle.net/canvasjs/rt1kmfrj/
$(function () {
// following things are used to customize
// set true to start with dynamic update, false to start with 0
var isDynamic = true;
// set to increase or decrease viewport size
var viewportSize = 10;
// how frequent dataPoints to be updated
var milliseconds = 1000;
var dataPoints = [
{y:10},
{y:14},
{y:0},
{y:20},
{y:14},
{y:7}
];
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Live Data Scroll"
},
axisY:{
gridThickness: 0,
},
data: [{
type: "line",
dataPoints: dataPoints
}]
});
chart.render();
var current = 0;
var scrollPane = $( ".scroll-pane" );
//while dynamic updating, number of datapoints to be visible
var dynamicWidth = viewportSize-10;
var updateChart = function () {
chart.options.data[0].dataPoints.push({
y: Math.random() * 10 + 5
});
if(!chart.options.axisX)
chart.options.axisX={viewportMinimum:null, viewportMaximum:null};
if(isDynamic){
chart.options.axisX.viewportMinimum = current - dynamicWidth;
chart.options.axisX.viewportMaximum = chart.options.axisX.viewportMinimum + viewportSize;
$( ".scroll-bar" ).
slider( "option", "value", chart.options.axisX.viewportMinimum + dynamicWidth);
}else{
chart.options.axisX.viewportMinimum = $( ".scroll-bar" ).slider( "option", "value" );
chart.options.axisX.viewportMaximum = chart.options.axisX.viewportMinimum + viewportSize;
}
$( ".scroll-bar" ).slider( "option", "max", current++ );
var newBarWidth = scrollPane.width() / current;
if(newBarWidth > 20){
scrollbar.find( ".ui-slider-handle" ).css({
width: newBarWidth,
"margin-left": -newBarWidth / 2
});
handleHelper.width( "" ).width( scrollbar.width() - newBarWidth );
}
chart.render();
};
setInterval(function () {
updateChart()
}, milliseconds);
var scrollbar = $( ".scroll-bar" ).slider({
max:6,
min:0,
slide: function( event, ui ) {
isDynamic = (ui.value === (current-1)) ? true : false;
}
});
var handleHelper = scrollbar.find( ".ui-slider-handle" )
.append( "<span class='ui-icon ui-icon-grip-dotted-vertical'></span>" )
.wrap( "<div class='ui-handle-helper-parent'></div>" ).parent();
scrollPane.css( "overflow", "hidden" );
scrollbar.find( ".ui-slider-handle" ).css({width: "102%"});
});
.scroll-pane { width: 100%; float:left; }
.scroll-bar-wrap { clear: left; padding: 0 4px 0 2px; margin: 0 -1px -1px -1px; }
.scroll-bar-wrap .ui-slider { background: none; border:0; height: 2em; margin: 0 auto; }
.scroll-bar-wrap .ui-handle-helper-parent { position: relative; width: 100%; height: 100%; margin: 0 auto; }
.scroll-bar-wrap .ui-slider-handle { top:.2em; height: 1.5em; }
.scroll-bar-wrap .ui-slider-handle .ui-icon { margin: -8px auto 0; position: relative; top: 50%; }
<link type="text/css" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://canvasjs.com/assets/script/canvasjs.min.js"></script>
<body>
<div class="scroll-pane ui-widget ui-widget-header ui-corner-all">
<div id="chartContainer" style="height: 400px; width: 100%;"></div>
<div class="scroll-bar-wrap ui-widget-content ui-corner-bottom">
<div class="scroll-bar"></div>
</div>
</div>
</body>
$(function () {
var dataPoints = [
{y:10},
{y:14},
{y:0},
{y:20},
{y:14},
{y:7}
];
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Live Data Scroll"
},
axisY:{
gridThickness: 0,
},
data: [{
type: "line",
dataPoints: dataPoints
}]
});
chart.render();
var current = 0;
var updateChart = function () {
chart.options.data[0].dataPoints.push({
y: Math.random() * 10 + 5
});
if(!chart.options.axisX)
chart.options.axisX={viewportMinimum:null, viewportMaximum:null};
chart.options.axisX.viewportMinimum = current++;
chart.render();
};
setInterval(function () {
updateChart()
}, 500);
$("#slider-range").slider({
range: "max",
min:0,
value:10,
slide: function (event, ui) {
current = ui.value;
$( "#slider-range" ).slider( "option", "max", dataPoints[dataPoints.length-1].x );
$( "#slider-range" ).slider( "value", current );
$( "#slider-range" ).slider( "option", "min", 0 );
}
});
});
<link type="text/css" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://canvasjs.com/assets/script/canvasjs.min.js"></script>
<body>
<div id="chartContainer" style="height: 400px; width: 100%;"></div>
<div id="slider-range" style="width:100%;"></div><br/><br/>
</body>
关于javascript - canvasjs:是否有可能回到过去?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36434223/
我正忙着尝试制作一个用于实时数据显示的 javascript 图表。我找到了这个 CanvasJS API。默认代码 specific chart他们的网页上的内容很好,但是当然,他们获取数据的部分,
我正在尝试使用 canvasJS 渲染两个动态图表,第一个图表正确渲染,实际上第二个图表正确填充,请参阅 inspect element 图像,但它没有显示在页面上。 这是界面,只显示一张图表 这是检
我正在尝试创建一个 dynamic chart in canvasjs 。如果数据点高于某个定义值,图表就会发生变化。我想知道您是否可以回到过去,以便可以滚动浏览动态图表。 亲切的问候,肯 最佳答案
我想根据 JSON 数组中的 N 个对象动态创建 CanvasJS 图表。如果 JSON 数组有 3 个对象,则网页应该能够显示 3 个图表。 通过id“spectraContainers”,我
我目前正忙于为老年患者建立商业智能环境。老年人戴着手环来测量加速度和心率。 心率部分将是一个静态图表(不是实时图表),我已经完成了。整个环境实际上已经完成了。实时加速度折线图除外。 所以我想使用Can
我想在图表中显示一些数据。大小约为 200k 数据点 x16 - 这是堆叠值。我希望这个库能够及时渲染这些数据。 数组看起来像:[16][250000],其中外部数组是堆叠值,内部数组保存数据。 [n
我正在尝试修改 Rendering a Chart from User Input for CanvasJS 的示例。我希望 x 轴成为时间线。我觉得我走在正确的轨道上,但现在陷入了设置正确的时间输入
我使用以下代码在 CanvasJS 中渲染 OHLC 图表: var candleData = []; var chart = new CanvasJS.Chart("chartContainer"
所以, 我得到一个对象,其中包含我想以这种形式(通过 Json)以下列形式绘制的数据: chartData(GraphData.year, GraphData.month, GraphData.day
我目前正在从事一个涉及 Bootstrap 和 CanvasJS 的元素,制作圆环图。 是否可以将类(class)标题和/或图例文本设为不间断文本?我一直在尝试包含 但它似乎不起作用。结果是“Le
window.onload = function() { var chart = new CanvasJS.Chart("chartContainer", { zoomEnabled: f
我正在使用 CanvasJs对于条形图,但我想根据屏幕大小进行不同的设置。 例如,对于小于 480 像素的屏幕,我想在 axisY 上完全隐藏标签。如何做到这一点? 似乎无法使用媒体查询和css 来自
我目前面临为 canvasJS 图表创建用户输入标题的问题。我目前正在浏览 canvasJS 上的教程,我认为创建一个面向用户输入的饼图会成为一个简洁的小项目。 我目前面临的问题是试图让从 HTML
我正在使用一个名为 CanvasJS 的安静漂亮的小 js 工具。它工作得很好,直到我需要它一次显示多个图表。 现在它只显示最后一个条目。其他一切都被忽略了。我几乎尝试了所有方法,但就是想不通为什么它
我正在使用 CanvasJs 渲染图表,它现在工作正常。虽然我不确定,但它是否以适当的方式在图表中显示数据。这是我正在使用的逻辑: var query = from c in GetProducts(
我正在尝试以类似于 dygraphs 功能( example here )的方式向我的 CanvasJS 图表添加注释,但尚未找到方法。我见过一个例子,他们用图像( here )替换了一个点,但它并不
我正在尝试创建一个条形图,其中包含 2009 年至 2015 年毛里求斯大学指定专业的在校学生的数据。我正在使用下面的 Javascript,console.log(data) 显示图表已呈现。但是,
我正在尝试使用 canvasJS 渲染多线图,但它没有按预期工作。 这是我的drawChart函数 function drawChart(obj, placeholder){ var dataPoin
我必须为网站创建饼图。在我看来,我无法根据我需要的数量动态渲染饼图。最多我必须渲染 28。所以,我想我必须输入 window.onload = function () { var chart
我正在尝试使用预先确定的数据(也称为来自数据库)在canvasjs中创建饼图。在 Canvasjs 方面,有一个有用的教程可以将多个数据放入图表中(使用弱类型数组),但我不知道如何为图例执行此操作。我
我是一名优秀的程序员,十分优秀!