ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Finance Chart - Crosshairs with Indicators
Posted by Travis on Aug-08-2015 00:00
This is for an aspx web page.  I'm attempting to add crosshairs (a vertical and horizontal
line) to my finance charts.   I felt the best approach was to modify the included
traceFinance javascript function.

I add a mouseY parameter like so:
function traceFinance(viewer, mouseX, mouseY) {...}

I then call it using:
traceFinance(viewer, viewer.getPlotAreaMouseX(), viewer.getPlotAreaMouseY());

Within the traceFinance, I draw my horizontal line:
// Get the plot area position relative to the entire FinanceChart
var plotArea = c.getPlotArea();
var plotAreaLeftX = plotArea.getLeftX() + c.getAbsOffsetX();
var plotAreaTopY = plotArea.getTopY() + c.getAbsOffsetY();

//draw a horizontal track line
viewer.drawHLine("trackHLine" + i, mouseY, plotArea.getLeftX(), plotArea.getRightX(),
"black 1px dotted");

Up to this point everything works great.  However the next section is where I'm
struggling.  I try to place a textbox on the right side of the chart showing the value of
the currently hovered y axis.
var yAxis = c.yAxis();
var xPos = yAxis.getX() + ((yAxis.getAlignment() == JsChartViewer.Left) ? -2 : 3);
var alignment = (yAxis.getAlignment() == JsChartViewer.Left) ? JsChartViewer.Right :
JsChartViewer.Left;
var labelStyle = "padding:2px 4px; font: bold 8pt arial; border:1px solid black;" +
                            "background-color:#DDDDFF; -webkit-text-size-adjust:100%;";
viewer.showTextBox("yAxisLabel" + i, xPos, mouseY, alignment, c.getYValue(mouseY,
yAxis).toPrecision(4), labelStyle);

The values appearing in the textbox are fine when I'm only displaying a primary stock
chart.  Once I add a technical indicator that appears on a separate panel (such as the
MACD), the values in the textbox for the horizontal trackline are wildly inaccurate.

I suspect the problem is the indicator has a different yAxis and that I need to show the
yAxis value for where the mouseover is happening (either the primary chart or indicator
panel).  I've tried determining this by seeing if the mouseY is within the range of the
given chart's top and bottom y, but I can't get it to work properly.

Any help is greatly appreciated.  I'd like for the crosshair to work regardless of how many
indicators are added.

  Re: Finance Chart - Crosshairs with Indicators
Posted by Peter Kwan on Aug-08-2015 01:53
Attachments:
Hi Travis,

I happened to have an example as attached.

Hope this can help.

Regards
Peter Kwan
financedemo_crosshair.aspx
financedemo_crosshair.aspx

46.24 Kb

  Re: Finance Chart - Crosshairs with Indicators
Posted by Travis on Aug-08-2015 02:09
Peter, that works like a charm.  Thank you very much!!