Displaying certain information when a datapoint is clicked.


Author
Message
David Huxtable
David Huxtable
Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)
Group: Forum Members
Posts: 13, Visits: 1
Good Afternoon,

I was wondering if it is possible to handle click events on individual data points?

My main goal is to be able to click on a datapoint and for it to print it's X and Y values, along with the name of the object it belongs to. For example, if I have two classes, fruit and vegetables, in which the instances of those classes are apple, banana and carrot. When clicking the data point I would like a print out of the name of the instance containing its x and y values, along with the instance name, such as carrot and then the class that derived from (vegatable).

So basically I am aiming for such a printout when the data point is clicked:
Type of food: Vegetable
Food name: Carrot
X: 6
Y: 12

Sorry fruit and vegetables was the first thing that popped in my head, perhaps I should have used car manufaturer and model or the like.

Any help would be greatly appreciated.

Thankyou in advance,

David
Reply
Blagovest Milanov
Blagovest Milanov
Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)Supreme Being (148 reputation)
Group: Forum Members
Posts: 154, Visits: 15

Hi David,

Fruits and vegetables are fine - actually there are many examples in the control that use them...

 

You have to intercept the click event of the control and then perform a hit test. The following code snippet shows how to do this:

 

private void Form1_Load(object sender, EventArgs e)

{

    NChart chart = nChartControl1.Charts[0];

    chart.BoundsMode = BoundsMode.Stretch;

    // add some sample data

    NBarSeries apples = new NBarSeries();

    NBarSeries oranges = new NBarSeries();

    Random rand = new Random();

    for (int i = 0; i < 10; i++)

    {

        apples.Values.Add(rand.Next(100));

        oranges.Values.Add(rand.Next(100));

    }

    apples.MultiBarMode = MultiBarMode.Clustered;

    oranges.MultiBarMode = MultiBarMode.Clustered;

    chart.Series.Add(apples);

    chart.Series.Add(oranges);

    nChartControl1.Refresh();

}

private void nChartControl1_MouseClick(object sender, MouseEventArgs e)

{

    NHitTestResult result = nChartControl1.HitTest(e.X, e.Y);

    if (result.ChartElement == ChartElement.DataPoint)

    {

        NBarSeries bar = (NBarSeries)result.Series;

        MessageBox.Show(bar.Values[result.DataPointIndex].ToString());

    }

}

Hope this helps - let me know if you meet any problems or have any questions.

 

Bob


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search