JS图表API与用户交互
JS charting API with user interaction
我正在寻找一个javascript图表API,它允许用户动态修改值点(通过拖放),然后提供一些回调来获得这些新值。
你有什么建议吗?
看看Awesome Free JavaScript Charts评论和另一篇
有一个用于highcharts的自定义插件,可以拖动图表点:http://jsfiddle.net/highcharts/AyUbx/:
(function (Highcharts) { var addEvent = Highcharts.addEvent, each = Highcharts.each; /** * Filter by dragMin and dragMax */ function filterRange(newY, series, XOrY) { var options = series.options, dragMin = options['dragMin' + XOrY], dragMax = options['dragMax' + XOrY]; if (newY < dragMin) { newY = dragMin; } else if (newY > dragMax) { newY = dragMax; } return newY; } Highcharts.Chart.prototype.callbacks.push(function (chart) { var container = chart.container, dragPoint, dragX, dragY, dragPlotX, dragPlotY; chart.redraw(); // kill animation (why was this again?) addEvent(container, 'mousedown', function (e) { var hoverPoint = chart.hoverPoint, options; if (hoverPoint) { options = hoverPoint.series.options; if (options.draggableX) { dragPoint = hoverPoint; dragX = e.pageX; dragPlotX = dragPoint.plotX; } if (options.draggableY) { dragPoint = hoverPoint; dragY = e.pageY; dragPlotY = dragPoint.plotY + (chart.plotHeight - (dragPoint.yBottom || chart.plotHeight)); } // Disable zooming when dragging if (dragPoint) { chart.mouseIsDown = false; } } }); addEvent(container, 'mousemove', function (e) { if (dragPoint) { var deltaY = dragY - e.pageY, deltaX = dragX - e.pageX, newPlotX = dragPlotX - deltaX - dragPoint.series.xAxis.minPixelPadding, newPlotY = chart.plotHeight - dragPlotY + deltaY, newX = dragX === undefined ? dragPoint.x : dragPoint.series.xAxis.translate(newPlotX, true), newY = dragY === undefined ? dragPoint.y : dragPoint.series.yAxis.translate(newPlotY, true), series = dragPoint.series, proceed; newX = filterRange(newX, series, 'X'); newY = filterRange(newY, series, 'Y'); // Fire the 'drag' event with a default action to move the point. dragPoint.firePointEvent( 'drag', { newX: newX, newY: newY }, function () { proceed = true; dragPoint.update([newX, newY], false); chart.tooltip.refresh(chart.tooltip.shared ? [dragPoint] : dragPoint); if (series.stackKey) { chart.redraw(); } else { series.redraw(); } }); // The default handler has not run because of prevented default if (!proceed) { drop(); } } }); function drop(e) { if (dragPoint) { if (e) { var deltaX = dragX - e.pageX, deltaY = dragY - e.pageY, newPlotX = dragPlotX - deltaX - dragPoint.series.xAxis.minPixelPadding, newPlotY = chart.plotHeight - dragPlotY + deltaY, series = dragPoint.series, newX = dragX === undefined ? dragPoint.x : dragPoint.series.xAxis.translate(newPlotX, true), newY = dragY === undefined ? dragPoint.y : dragPoint.series.yAxis.translate(newPlotY, true); newX = filterRange(newX, series, 'X'); newY = filterRange(newY, series, 'Y'); dragPoint.update([newX, newY]); } dragPoint.firePointEvent('drop'); } dragPoint = dragX = dragY = undefined; } addEvent(document, 'mouseup', drop); addEvent(container, 'mouseleave', drop); }); /** * Extend the column chart tracker by visualizing the tracker object for small points */ var colProto = Highcharts.seriesTypes.column.prototype, baseDrawTracker = colProto.drawTracker; colProto.drawTracker = function () { var series = this; baseDrawTracker.apply(series); each(series.points, function (point) { point.graphic.attr(point.shapeArgs.height < 3 ? { 'stroke': 'black', 'stroke-width': 2, 'dashstyle': 'shortdot' } : { 'stroke-width': series.options.borderWidth, 'dashstyle': series.options.dashStyle || 'solid' }); }); }; })(Highcharts);
相关文章:
- Javascript没有't更新DOM,直到用户交互
- 使用JavaScript验证用户交互/输入-这是一种很好的方法
- Ajax 调用在 IOS 中的用户交互之前不起作用
- 在C#中,我如何对客户端用户交互和javascript(jQuery)代码进行单元测试
- JavaScript/Wicket:如何显示阻止用户交互的覆盖
- 对用户交互进行单选按钮检查
- 谷歌应用程序脚本:如何在没有用户交互的情况下调用绑定到处理程序的函数
- 用户交互启用了 Javascript
- 设置用户交互计时器
- HTML5 + JS:跟踪用户交互
- 是否可以像真实用户交互那样进行JavaScript操作来更改文档的activeElement
- HTML,JS:加载音频是否需要在移动浏览器上进行用户交互
- 有没有办法防止用户交互暂停动画
- 跟踪网站上的用户交互
- 我可以在手机上自动播放上一页用户交互的音频吗
- 从web应用程序,如何在没有用户交互的情况下在客户端计算机上运行exe
- 如何确定onStateChange事件是由API还是用户交互触发的
- 任何不需要用户交互的可视化库
- 检测任何用户交互
- 用户交互后,后台出现Javascript弹出窗口