gpt4 book ai didi

javascript - 使用Teechart按时间间隔手动绘制yaxis

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:14 25 4
gpt4 key购买 nike

我正在使用 Teechart 库以 1 秒的时间间隔显示 y 轴。 Chart1.axes.left.increment = 1;帮助我以 1 的间隔增加 yaxis。我需要的是在这些实线之间布置虚线。我想以 0.20 秒的时间间隔手动添加虚线的线系列。如何使用线系列在这里添加虚线。

 function draw_TeeChart() {

var w = window.innerWidth, h = window.innerHeight;

// Initialize Teechart[![enter image description here][1]][1]
Chart1 = new Tee.Chart("canvas");

document.getElementById("canvas").style.position = "relative";
document.getElementById("canvas").width= Math.round(0.82*w);document.getElementById("canvas").height= Math.round(0.89*h); //Chart1.bounds.x = Math.round(0.01*w);

Chart1.bounds.x = 14;Chart1.bounds.y= 10;
Chart1.bounds.width = Math.round(chartW*w);Chart1.bounds.height= Math.round(0.88*h);
Chart1.legend.visible = false; Chart1.panel.transparent = true;
Chart1.title.visible = false;Chart1.axes.bottom.title.text = " ";
Chart1.axes.left.increment = 1;


Chart1.axes.bottom.increment=1;

Chart1.axes.bottom.innerTicks.visible = true;
Chart1.axes.bottom.ticks.length = 9;
Chart1.axes.bottom.ticks.stroke.fill = "blue";

Chart1.axes.bottom.minorTicks.visible = true;
Chart1.axes.bottom.minorTicks.length = 4;
Chart1.axes.bottom.minorTicks.count = 4;
Chart1.axes.bottom.minorTicks.stroke.fill = "green";



// var dottedLines = Chart1.axes.bottom.increment=.2;


// var increment = 0.20;
// var dottedLines = Chart1.axes.bottom.grid.format.stroke.dash = [5,3];
// var solidLines = Chart1.axes.bottom.increment=1;


// for(increment =0.20;increment<100;increment =increment+0.20){

// if (increment % 1 == 0) {

// Chart1.axes.bottom.increment=1;
// }
// else {
// Chart1.axes.bottom.increment=0.20;
// Chart1.axes.bottom.grid.format.stroke.dash = [5,3];
// }

// }

Chart1.walls.back.format.fill = wallColorCode;
Chart1.walls.back.format.shadow.visible = false;
document.body.style.cursor = "pointer";

document.getElementById("EventCount").value = event_time.length.toFixed(0);

}

图 1:as shown in the image above i have added solid lines for 0.20 time interval. but all i want is to add dotted lines for 0.20 intervals and solid line s at 1,2,3 and so on.

图 2: as a latest progress i have managed to get 4 ticks in the interval of 4. is it possible to extend these ticks inwards to extend it further to be dotted lines?

enter image description here

最佳答案

此处的示例显示了如何扩展底部轴,添加新的 innerGrid 属性并在 drawLabel 覆盖中使用它。

var Chart1;

function draw() {
Chart1 = new Tee.Chart("canvas1");

var line1 = Chart1.addSeries(new Tee.Line());
line1.data.values = [10, 20, 30, 20, 50];

Chart1.legend.visible = false;

Chart1.axes.bottom.setMinMax(0, 5);
Chart1.axes.bottom.increment = 1;
Chart1.axes.bottom.innerTicks.visible = true;
Chart1.axes.bottom.ticks.length = 9;
Chart1.axes.bottom.ticks.stroke.fill = "blue";
Chart1.axes.bottom.minorTicks.visible = true;
Chart1.axes.bottom.minorTicks.length = 4;
Chart1.axes.bottom.minorTicks.count = 4;
Chart1.axes.bottom.minorTicks.stroke.fill = "green";

Chart1.axes.bottom.innerGrid = [];
Chart1.axes.bottom.innerGrid.increment = 0.20;
Chart1.axes.bottom.innerGrid.format = new Tee.Format(Chart1);
Chart1.axes.bottom.innerGrid.format.stroke.fill = Chart1.axes.bottom.grid.format.stroke.fill;
Chart1.axes.bottom.innerGrid.format.stroke.dash = [5, 3];
Chart1.axes.bottom.oldDrawLabel = Chart1.axes.bottom.drawLabel;

Chart1.axes.bottom.drawLabel = function(value, r) {
this.oldDrawLabel(value, r);

var c = this.chart.ctx,
rect = this.chart.chartRect,
f = this.innerGrid.format,
tmpX;

var tmpValue = value + this.innerGrid.increment;

while (tmpValue < value + this.increment) {
tmpX = Chart1.axes.bottom.calc(tmpValue);

if ((tmpX > rect.x) && (tmpX < rect.x + rect.width)) {
c.beginPath();

c.moveTo(tmpX, rect.y);
c.lineTo(tmpX, rect.y + rect.height);

f.stroke.prepare();
c.stroke();
}

tmpValue += this.innerGrid.increment;
}

//draw innerGrid between the axis minimum and the first label. Happens when scrolled
if (value - this.increment <= this.minimum) {
tmpValue = value - this.innerGrid.increment;

while (tmpValue > value - this.increment) {
tmpX = Chart1.axes.bottom.calc(tmpValue);

if ((tmpX > rect.x) && (tmpX < rect.x + rect.width)) {
c.beginPath();

c.moveTo(tmpX, rect.y);
c.lineTo(tmpX, rect.y + rect.height);

f.stroke.prepare();
c.stroke();
}

tmpValue -= this.innerGrid.increment;
}
}
};
Chart1.draw();
}
<!DOCTYPE html>
<html lang="en">

<head>
<script src="http://www.steema.com/files/public/teechart/html5/latest/src/teechart.js" type="text/javascript"></script>
</head>

<body onload="draw()">
<canvas id="canvas1" width="500" height="300">
This browser does not seem to support HTML5 Canvas.
</canvas>
</body>

</html>

关于javascript - 使用Teechart按时间间隔手动绘制yaxis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46923494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com