Hi Syncfusion Support,
I have two very specific behaviors to achieve with the
“Chart” component and I would like to know if it is possible. To simply put it,
I want to be able to click ANYWHERE on the graph and get the index of that
point. I am already aware of the “pointClick” event, but it only works if you
click directly on a specific “data point”.
First of all, allow me to concretely explain my query
with the graph image below. If we look at the purple line in the graph, we can
see that there are only 3 “specific” points that you can get the “pointClick”
event to trigger on: (x: 1, y: 0.2mg) (x: 9, y: 0.1mg) (x: 18, y: 0.1mg). As an
example, I would like to be able to click on the index (x: 9, y: 0.900mg) and
retrieve that index information to display it somewhere else in my page. That
index could be anywhere on my graph and it would not be limited to a specific
point.
Second of all, I would also like to be able to click anywhere on my graph and
draw a vertical line to retrieve any indexes that cross that line. Allow me to
explain this second query again with the image below. After clicking the graph
where the mouse is positioned in the image, the red line appears and I would
like to retrieve the 3 indexes that cross that line (1 index for each colored
line).
Thank you
App.component.html:
<ejs-chart #chart (chartMouseClick)="mouseClick($event)" [crosshair]="crosshair">
// add your additional code here
</ejs-chart>
App.component.ts:
// add your additional code here
public mouseClick(args: IMouseEventArgs): void {
if (args.target.indexOf("_ChartAreaBorder" || "_MajorGridLine_") != -1) {
let mouseX = args.x;
let mouseY = args.y;
let xAxis = this.chart.series[0]["xAxis"];
let yAxis = this.chart.series[0]["yAxis"];
let rect = this.chart.series[0]["clipRect"];
let xVal = mouseX - rect.x;
let yVal = mouseY - rect.y;
let xSize = rect.width;
let ySize = rect.height;
let actualXValue = !xAxis.isInversed ? xVal / xSize : 1 - xVal / xSize;
actualXValue =
actualXValue * xAxis.visibleRange.delta + xAxis.visibleRange.min;
let actualYValue = yAxis.isInversed ? yVal / ySize : 1 - yVal / ySize;
actualYValue =
actualYValue * yAxis.visibleRange.delta + yAxis.visibleRange.min;
let xDate = new Date(actualXValue);
console.log(xDate);
}
}
// add your additional code here |