Applies to: Nevron Chart for .NET
How to store custom data in chart data points?
To store custom information for data point in Nevron Chart, you can use the Tags data series. You can work with Tags data series the same way as with the FillStyles or BorderStyles data series, but you can store any type of object. For example, the following code stores a custom object of type MyCustomData for the data point at index 5:
series.Tags[5] = new MyCustomData("some string", 42);
You can also work with the tags through the data point interface.
The following code example demonstrates how to use the Tags data series:
[C#]
using
System;
using
System.Windows.Forms;
using
Nevron.Chart;
...
private
void
Form1_Load(
object
sender, EventArgs e)
{
NBarSeries bar =
new
NBarSeries();
bar.Values.AddRange(
new
double
[] { 10, 20, 30, 17, 23 });
bar.Tags[0] =
"str 0"
;
bar.Tags[1] =
"str 1"
;
bar.Tags[2] =
"str 2"
;
bar.Tags[3] =
"str 3"
;
bar.Tags[4] =
"str 4"
;
NChart chart = nChartControl1.Charts[0];
chart.Series.Add(bar);
nChartControl1.MouseDown +=
new
MouseEventHandler(nChartControl1_MouseDown_Variant2);
}
void
nChartControl1_MouseDown_Variant1(
object
sender, MouseEventArgs e)
{
NHitTestResult htr = nChartControl1.HitTest(e.Location);
if
(htr.ChartElement == ChartElement.DataPoint)
{
NSeries series = htr.Series
as
NSeries;
if
(series !=
null
)
{
object
obj = series.Tags[htr.DataPointIndex];
if
(obj !=
null
)
{
MessageBox.Show(obj.ToString());
}
}
}
}
void
nChartControl1_MouseDown_Variant2(
object
sender, MouseEventArgs e)
{
NHitTestResult htr = nChartControl1.HitTest(e.Location);
if
(htr.ChartElement == ChartElement.DataPoint)
{
NDataPoint dp = htr.Object
as
NDataPoint;
if
(dp !=
null
)
{
object
obj = dp[DataPointValue.Tag];
if
(obj !=
null
)
{
MessageBox.Show(obj.ToString());
}
}
}
}
[VB.NET]
Imports
Microsoft.VisualBasic
Imports
System
Imports
System.Windows.Forms
Imports
Nevron.Chart
...
Private
Sub
Form1_Load(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
MyBase
.Load
Dim
bar
As
NBarSeries =
New
NBarSeries()
bar.Values.AddRange(
New
Double
() { 10, 20, 30, 17, 23 })
bar.Tags(0) =
"str 0"
bar.Tags(1) =
"str 1"
bar.Tags(2) =
"str 2"
bar.Tags(3) =
"str 3"
bar.Tags(4) =
"str 4"
Dim
chart
As
NChart = nChartControl1.Charts(0)
chart.Series.Add(bar)
AddHandler
nChartControl1.MouseDown,
AddressOf
nChartControl1_MouseDown_Variant2
End
Sub
Private
Sub
nChartControl1_MouseDown_Variant1(
ByVal
sender
As
Object
,
ByVal
e
As
MouseEventArgs)
Dim
htr
As
NHitTestResult = nChartControl1.HitTest(e.Location)
If
htr.ChartElement = ChartElement.DataPoint
Then
Dim
series
As
NSeries = TryCast(htr.Series, NSeries)
If
Not
series
Is
Nothing
Then
Dim
obj
As
Object
= series.Tags(htr.DataPointIndex)
If
Not
obj
Is
Nothing
Then
MessageBox.Show(obj.ToString())
End
If
End
If
End
If
End
Sub
Private
Sub
nChartControl1_MouseDown_Variant2(
ByVal
sender
As
Object
,
ByVal
e
As
MouseEventArgs)
Dim
htr
As
NHitTestResult = nChartControl1.HitTest(e.Location)
If
htr.ChartElement = ChartElement.DataPoint
Then
Dim
dp
As
NDataPoint = TryCast(htr.
Object
, NDataPoint)
If
Not
dp
Is
Nothing
Then
Dim
obj
As
Object
= dp(DataPointValue.Tag)
If
Not
obj
Is
Nothing
Then
MessageBox.Show(obj.ToString())
End
If
End
If
End
If
End
Sub
Article ID: 181, Created On: 3/7/2011, Modified: 3/7/2011