Home forums Using CanvasJS dataPointIndex of scatter

This topic contains 1 reply, has 2 voices, and was last updated by  Sunil Urs 1 year, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #8540

    dwpark
    Participant

    I want to know dataPointIndex of scatter chart.
    In the example below, the alert message of first point is “scatter, dataPoint {x:10, y:34}, index=0”
    However, the actual index of “{x:10, y:34}” is 1.
    I guess that the dataPoint is sorted.
    Is there a way to get the original index?

    var chart = new CanvasJS.Chart(“chartContainer”,
    {
    title:{
    text: “Attaching Mouse Over event on dataSeries”
    },
    data: [
    {
    type: “scatter”,
    mouseover: onMouseover,
    dataPoints: [
    { x: 20, y: 45},
    { x: 10, y: 34},
    { x: 30, y: 19 },
    { x: 40, y: 75 },
    { x: 50, y: 15 },
    { x: 60, y: 60 },
    { x: 70, y: 48 },
    { x: 80, y: 04 },
    { x: 90, y: 35}
    ]
    }
    ]
    });
    chart.render();

    function onMouseover(e){
    alert( e.dataSeries.type+ “, dataPoint { x:” + e.dataPoint.x + “, y: “+ e.dataPoint.y + ” }, index=” + e.dataPointIndex );
    }

    #8564

    Sunil Urs
    Keymaster

    dwpark,

    As of we dataPoints are automatically sorted in case of scatter & bubble charts. We’ll consider changing this behavior in upcoming versions.

    As a workaround you can store the index value of dataPoints yourself and access them inside the event handler.

    Here is an example.


    Sunil Urs

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.