mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-13 07:58:41 +00:00
OHLC chart implemented
This commit is contained in:
parent
4aacdb499b
commit
ecd186ff6a
|
|
@ -96,14 +96,34 @@
|
||||||
|
|
||||||
this.chart.drawGrid(svg, xGrid, yGrid);
|
this.chart.drawGrid(svg, xGrid, yGrid);
|
||||||
|
|
||||||
svg.selectAll("rect")
|
if(this.chart.subtype === 'candlestick') {
|
||||||
.data(this.chart.dataset[0].points)
|
svg.selectAll("rect")
|
||||||
.enter().append("svg:rect")
|
.data(this.chart.dataset[0].points)
|
||||||
.attr("x", function(d) { return x(d.x)-mm/10; })
|
.enter().append("svg:rect")
|
||||||
.attr("y", function(d) {return y(Math.max(d.open, d.close));})
|
.attr("x", function(d) { return x(d.x)-mm/10; })
|
||||||
.attr("height", function(d) { return Math.max(1, y(Math.min(d.open, d.close))-y(Math.max(d.open, d.close)));})
|
.attr("y", function(d) {return y(Math.max(d.open, d.close));})
|
||||||
.attr("width", function(d) { return 0.5 * (self.chart.dimension.width - 4*mm)/self.chart.dataset[0].points.length; })
|
.attr("height", function(d) { return Math.max(1, y(Math.min(d.open, d.close))-y(Math.max(d.open, d.close)));})
|
||||||
.attr("fill",function(d) { return d.open > d.close ? "red" : "green" ;});
|
.attr("width", function(d) { return 0.5 * (self.chart.dimension.width - 4*mm)/self.chart.dataset[0].points.length; })
|
||||||
|
.attr("fill",function(d) { return d.open > d.close ? "red" : "green" ;});
|
||||||
|
} else {
|
||||||
|
let datapoint = svg.selectAll("rect")
|
||||||
|
.data(this.chart.dataset[0].points)
|
||||||
|
.enter();
|
||||||
|
|
||||||
|
datapoint.append("svg:rect")
|
||||||
|
.attr("x", function(d) { return x(d.x)-mm/10; })
|
||||||
|
.attr("y", function(d) {return y(d.open);})
|
||||||
|
.attr("height", function(d) { return 1;})
|
||||||
|
.attr("width", function(d) { return 0.25 * (self.chart.dimension.width - 4*mm)/self.chart.dataset[0].points.length; })
|
||||||
|
.attr("fill",function(d) { return d.open > d.close ? "red" : "green" ;});
|
||||||
|
|
||||||
|
datapoint.append("svg:rect")
|
||||||
|
.attr("x", function(d) { return x(d.x); })
|
||||||
|
.attr("y", function(d) {return y(d.close);})
|
||||||
|
.attr("height", function(d) { return 1;})
|
||||||
|
.attr("width", function(d) { return 0.25 * (self.chart.dimension.width - 4*mm)/self.chart.dataset[0].points.length; })
|
||||||
|
.attr("fill",function(d) { return d.open > d.close ? "red" : "green" ;});
|
||||||
|
}
|
||||||
|
|
||||||
svg.selectAll("line.stem")
|
svg.selectAll("line.stem")
|
||||||
.data(this.chart.dataset[0].points)
|
.data(this.chart.dataset[0].points)
|
||||||
|
|
|
||||||
25
Chart/OhlcChart.js
Normal file
25
Chart/OhlcChart.js
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
(function (jsOMS)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
jsOMS.Chart.OhlcChart = function (id)
|
||||||
|
{
|
||||||
|
this.chart = new jsOMS.Chart.CandlestickChart(id);
|
||||||
|
this.chart.getChart().subtype = 'ohlc';
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.Chart.OhlcChart.prototype.getChart = function ()
|
||||||
|
{
|
||||||
|
return this.chart.getChart();
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.Chart.OhlcChart.prototype.setData = function (data)
|
||||||
|
{
|
||||||
|
this.chart.setData(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.Chart.OhlcChart.prototype.draw = function ()
|
||||||
|
{
|
||||||
|
return this.chart.draw();
|
||||||
|
};
|
||||||
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
Loading…
Reference in New Issue
Block a user