Profile Picture

Displaying certain information when a datapoint is clicked.

Posted By David Huxtable 15 Years Ago

Displaying certain information when a datapoint is clicked.

Author
Message
David Hohl
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 0, Visits: 1
Bob,

Thanks for the sample code. I had found help info on tooltips yesterday, but was trying to figure out how to assign one to an NDataPoint object. I did not realize that I have to assign a set of tooltips to the series. Plus, even though I had a tooltip object assigned to the form, I did not know I needed one for the chart control object also. With those two changes things are working fine.

Thanks again!

--Dave

bob milanov
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi David,

I see - check out the following code:

NChart chart = nChartControl1.Charts[0];

NPointSeries point = new NPointSeries();
chart.Series.Add(point);

point.UseXValues = true;
point.DataLabelStyle.Visible = false;

// add some dummy data
point.Values.Add(10);
point.XValues.Add(10);

point.Values.Add(20);
point.XValues.Add(20);

point.Values.Add(30);
point.XValues.Add(30);

// assign tooltips
for (int i = 0; i < point.Values.Count; i++)
{
 string tooltip = string.Format("X: {0}, Y: {1}", point.XValues[i], point.Values[i]); 
 point.InteractivityStyles.Add(i, new NInteractivityStyle(tooltip));
}

nChartControl1.Controller.Tools.Add(new NTooltipTool());

Generally you need to assign some sort of interactivity style to the objects you want to have tooltips. All chart elements supports it (labels, legend data items, chart walls etc.). In the case above I assign interactitivy style by looping through the point x/y values. Note that you need to add a tooltip tool to the chart controller. In the case of WebForms the last line should be:

NHtmlImageMapResponse imageMapResponse = new NHtmlImageMapResponse();
nChartControl1.ServerSettings.BrowserResponseSettings.DefaultResponse = imageMapResponse;

More information on this can be found at:
http://help.nevron.com/dotnetvision/UsersGuide_Interactivity_Interactivity_Overview.html

Questions or comments - feel free...

Best regards,
Bob

 

 



David Hohl
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 0, Visits: 1
Bob,

A tooltip would be fine. In fact, I was trying to find out how to do a tooltip in Nevron Chart, but could not find any info in Help about it. Maybe I did not look in the right places.

If you could show me how to set things up so a tool tip showing the (x,y) info for a data point pops up when the mouse moves over the point, that would be exactly what I need.

Thanks,

Dave

bob milanov
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi David,

Will a simple tooltip do the job or you want to have the possibility to show different content besides text? I'm asking as the tooltip is a build in feature of the control...

Best regards,
Bob

 



David Hohl
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 0, Visits: 1
Bob,

I am trying to do something similar, but a bit more complicated (I think).

I am trying to convert from using Microsoft's OWC11 AxChartSpace to using Nevron Chart. A default feature of AxChartSpace is when the mouse hovers over a data point the x and y coordinates pop up in a small box, which disappears when the mouse moves off the data point. I tried using your code snippet for a mouse hover event handler, but it complained about e.X and e.Y not existing. Even if I had gotten that working, I did not see how to make the message box go away automatically when the mouse moved off the data point.

Any ideas on how this could be done?

Thanks,

Dave

David Huxtable
Posted 15 Years Ago
View Quick Profile
Junior Member

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
Last Active: 15 Years Ago
Posts: 13, Visits: 1
Thank you very much Bob,

yes tags will do very nicely, I can't believe I didn't think of them. I was overcomplicating my requirements, I seem to do that a little too often.

Thank you again Bob, you have made life much easier for me

David

bob milanov
Posted 15 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi David,

I noticed some Nevron bar chart examples using fruit & veg, I guess that was why I had fruit and veg on the brain
Yes this also crossed my mind

You can add tags to the data points/series in the same way you can add individual fill styles, stroke etc. Following is the revised code that shows how to tag data points:

 

class NFruitTag

{

    public NFruitTag(string tag)

    {

        m_Tag = tag;

    }

 

    public string m_Tag;

}

 

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));

        apples.Tags.Add(i, new NFruitTag("Apple " + i.ToString()));

 

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

        oranges.Tags.Add(i, new NFruitTag("Orange " + i.ToString()));

    }

 

    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(((NFruitTag)bar.Tags[result.DataPointIndex]).m_Tag);

    }

}

Is this the feature you're looking for?



David Huxtable
Posted 15 Years Ago
View Quick Profile
Junior Member

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
Last Active: 15 Years Ago
Posts: 13, Visits: 1
Thank you for your speedy reply Bob,

I noticed some Nevron bar chart examples using fruit & veg, I guess that was why I had fruit and veg on the brain

Your post helped, however what I was trying to achieve, was to be able to display properties of the object the data point relates to. For instance, if I had a class named Vegetable, consisting of a VegID property and then I have a objects named carrot, potatoe and onion, consiting of the following properties:
- VegID
- Name
- Colour
- PopularityPercent(NDatapPoint's Y value).

I was hoping there was a way that I could print the information of these properties, when clicking on the respected data point. I thought that perhaps these properties could be added to the NDataPoint, perhaps through extension or inheritence. I tried using extensions and then realised an enum was used as to look for data points in the click event so this wouldn't help.

if there is a way such can be achieved any help will be greatly appreciated.

i apologise for explaining myself clearly in my last post.

Thank you again Bob,

David

bob milanov
Posted 15 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

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



David Huxtable
Posted 15 Years Ago
View Quick Profile
Junior Member

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
Last Active: 15 Years Ago
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



Similar Topics


Reading This Topic