.netCHARTING v10.5 Documentation
Custom Data Attributes

Custom element attributes.

Additional information stored in databases can be extracted and used in a chart to provide further information in a tool tip, an element's label, within the element's hot spot URL, and any other related text strings.

Extracting from a database

Extracting attributes from a database can be accomplished with a single line of code using the DataFields property of a DataEngine object..

Assume the following database columns:

  • EmployeeID
  • FullName
  • Department
  • EmailAddress
  • PhoneNumber
  • AveragePerformance

 

Using this database we will create a chart that shows each employee's name on the x axis and they're average performance on the y axis. When we mouse over a column in the chart we want to see the employee's ID, department, and phone number. When we click a given column we want to send the employee an email.

The first step is to specify the DataFields property.

[C#]
DataEngine de = new DataEngine();
de.ConnectionString = "...";
de.SqlStatement =  "SELECT * FROM
myTable";  de.DataFields="xAxis=FullName,yAxis=AveragePerformance,id=EmployeeID,"
+ "department=Department,email=EmailAddress,phone=PhoneNumber";


[Visual Basic] Dim de As New DataEngine() de.ConnectionString = "..." de.SqlStatement = "SELECT * FROM myTable" de.DataFields="xAxis=FullName,yAxis=AveragePerformance,id=EmployeeID,"_
& "department=Department,email=EmailAddress,phone=PhoneNumber"

The next step is to specify a template for the element's tooltip and url.

[C#]
Chart.DefaultSeries.DefaultElement.ToolTip = "ID: %id \n Department: %department \n Phone Number: %phone";
Chart.DefaultSeries.DefaultElement.URL = "mailto:%email";
[Visual Basic]
Chart.DefaultSeries.DefaultElement.ToolTip = "ID: %id " & vbCrLf &
" Department: %department " & vbCrLf & " Phone Number: %phone"
Chart.DefaultSeries.DefaultElement.URL = "mailto:%email"

This complex and highly functional chart is now ready.

Adding manually

Element attributes can be populated manually using the following method.

[C#]
Element e = new Element();
e.Name = "myElement";
e.YValue = 15;
e.CustomAttributes["Phone"] = "555-8593";
e.CustomAttributes["Department"] = "Marketing";

[Visual Basic] Dim e As New Element()
e.Name = "myElement" e.YValue = 15 e.CustomAttributes("Phone") = "555-8593" e.CustomAttributes("Department") = "Marketing"

Series Level attributes

Attributes can be added at the series level to specify information common to all elements. These can be used in legend entry labels, legend entry tool tips and URLs.

Let's generate a SeriesCollection using the data engine object from the above example but we will modify it to only extract elements from a specific department.

[C#]
de.SqlStatement = "SELECT * FROM myTable WHERE department = "marketing";
SeriesCollection sc = de.GetSeries();
// The above generated 1 series with a number of employee elements.
// Now we can add some attributes for this specific to the marketing department.
sc[0].Name = "Marketing";
sc[0].DefaultElement.CustomAttributes["DepartmentPhoneNumber"] = "555-2414";
sc[0].DefaultElement.CustomAttributes["DepartmentManagerName"] = "555-2414";
sc[0].DefaultElement.CustomAttributes["DepartmentAddress"] = "555-2414";
[Visual Basic]
de.SqlStatement = "SELECT * FROM myTable WHERE department = "marketing"
Dim sc As SeriesCollection sc = de.GetSeries() ' The above generated 1 series with a number of employee elements. ' Now we can add some attributes for this specific to the marketing department. sc(0).Name = "Marketing" sc(0).DefaultElement.CustomAttributes("DepartmentPhoneNumber") = "555-2414" sc(0).DefaultElement.CustomAttributes("DepartmentManagerName") = "555-2414" sc(0).DefaultElement.CustomAttributes("DepartmentAddress") = "555-2414"

The series now has additional information stored. Let's use it in the series' legend entry tool tip.

[C#]
Chart.DefaultSeries.LegendEntry.ToolTip = "Manager: %DepartmentManager \n "
+ "Phone: %DepartmentPhoneNumber \n Address: %DepartmentAddress"; // Elements can also use the series level attributes Chart.DefaultSeries.DefaultElement.ToolTip = "%Name \n Phone #: %phone \n "
+ "Department Phone #: %DepartmentPhoneNumber";
[Visual Basic]
Chart.DefaultSeries.LegendEntry.ToolTip = "Manager: %DepartmentManager \r "_
& "Phone: %DepartmentPhoneNumber " & vbCrLf & " Address: %DepartmentAddress"; ' Elements can also use the series level attributes Chart.DefaultSeries.DefaultElement.ToolTip = "%Name " & vbCrLf & " Phone #: %phone "_
& vbCrLf & " " & "Department Phone #: %DepartmentPhoneNumber"

The above may tool tips may look like this:

John Doe 
Phone #: 555-5426
Department Phone #: 555-1349

 

Sample: customAttributes.aspx