html - 选中的获取点在teechart中
问题描述
尝试在 mouseup 后在选定区域中获取系列值。需要计算所选的宽度和高度都在图表中相对于轴。
[`https://jsbin.com/wapovohiwe/edit?html,output`][1]
解决方案
我修改了您的示例以绘制矩形并输出
Chart1 = new Tee.Chart("canvas");
Chart1.legend.visible = false;
Chart1.panel.format.gradient.visible = false;
Chart1.panel.format.fill = "white";
Chart1.walls.back.format.fill = "white";
Chart1.addSeries(new Tee.Line([1, 3, 0, 2, 7, 5, 6]));
Chart1.zoom.enabled = false;
var myFormat = new Tee.Format(Chart1);
myFormat.transparency = 0.9;
var rect = {},
drag = false;
Chart1.mousedown = function(e) {
rect.startX = e.x - canvas.offsetLeft - canvas.parentElement.offsetLeft - canvas.parentElement.parentElement.offsetLeft;
rect.startY = e.y - canvas.offsetTop - canvas.parentElement.offsetTop - canvas.parentElement.parentElement.offsetTop;
drag = true;
}
Chart1.mouseup = function(p) {
var i, tmpP = {};
points = [];
var s = Chart1.series.items[0];
for (i = 0; i < s.count(); i++) {
s.calc(i, tmpP);
if ((tmpP.x >= rect.startX) && (tmpP.x <= rect.startX + rect.w) && (tmpP.y >= rect.startY) && (tmpP.y <= rect.startY + rect.h))
console.log("index: " + i + ", value: " + s.data.values[i]);
}
drag = false;
}
Chart1.mousemove = function(e) {
if (drag) {
rect.w = e.x - rect.startX;
rect.h = e.y - rect.startY;
drawChart();
}
}
function drawChart() {
Chart1.draw();
myFormat.rectangle(rect.startX, rect.startY, rect.w, rect.h);
}
Chart1.draw();
<script src="https://www.steema.com/files/public/teechart/html5/latest/src/teechart.js"></script>
<canvas id="canvas" height="400" width="700"></canvas>
推荐阅读
- c++ - 为表示一个或多个操作的 C++ 函数查找 int 参数的类型安全替换
- git - 在drupal 8中安装模块时作曲家抛出git错误
- typescript - 将类型分配给可能不需要解析的 JSON 类型
- java - 活动中的 Android 工作室名称选项卡
- sql - 我可以合并或加入这些表吗?
- c# - 如何在 ASP.NET 中使用视图模型?
- php - 即使 WP_DEBUG=true,Wordpress 也不会写入 debug.log
- quill - Quill:如何获取包含样式的 html 数据?
- python - 当您在 if 逻辑语句中调用修改函数时,是否会编辑 2D 列表?
- javascript - 如何使用 Javascript 本地存储从 HTML 文本框中存储值?