How to: Show Custom Data in a Web Chart Using ASPxPopupControl
- 3 minutes to read
This example demonstrates how to show custom data obtained from a WebChartControl data source, when a mouse pointer hovers over a series point. To implement this, add an ASPxCallbackPanel to the ASPxPopupControl, so that data is obtained during its callbacks.
Do the following to implement tooltips for a Web chart.
- Create a new ASP.NET Web Application or open an existing one.
- Drop a chart onto the Web page, and bind it to a data source.
Drop an ASPxPopupControl from the DX.24.2: Navigation & Layout toolbox tab onto the page.
Set its ASPxPopupControlBase.ClientInstanceName property to pc.
Drop an ASPxCallbackPanel from the same toolbox tab onto ASPxPopupControl1.
Set its ASPxPanelBase.ClientInstanceName property to cbp.
Switch to the DX.24.2: Common Controls toolbox tab, and place two ASPxLabel controls within ASPxCallbackPanel1.
Select ASPxCallbackPanel1 and click its smart tag. In the invoked Tasks list, click Client-Side Events….
In the invoked dialog, handle the CallbackClientSideEventsBase.EndCallback event in the following way.
function(s, e) { pc.SetHeaderText(s.cpHeaderText); pc.ShowAtPos(pcX, pcY); }
In a similar way, select the chart and click its smart tag. In its Tasks list, click Client-Side Events….
In the invoked dialog, handle the ChartClientSideEvents.ObjectSelected event in the following way.
function(s, e) { if (e.hitInfo.inSeries) { var obj = e.additionalHitObject; if (obj != null){ pcX = e.absoluteX; pcY = e.absoluteY; cbp.PerformCallback(obj.argument); } } }
Handle the ASPxCallbackPanel.Callback event as follows.
using System; using System.Data; using System.Web.UI; using System.Collections; using DevExpress.Web; // ... string headerText = null; protected void ASPxCallbackPanel1_Callback(object sender, CallbackEventArgsBase e) { String param = e.Parameter.Replace("'", "''"); AccessDataSource1.SelectCommand = "SELECT * FROM [Products] WHERE ProductName = '" + param + "'"; IEnumerable data = AccessDataSource1.Select(DataSourceSelectArguments.Empty); foreach (DataRowView row in data) { ASPxLabel1.Text = "Price: " + row["UnitPrice"].ToString(); ASPxLabel2.Text = "Units in Stock: " + row["UnitsInStock"].ToString(); headerText = row["ProductName"].ToString(); break; } }
Add the following code to the ASPxPanelBase.CustomJSProperties event handler.
Run the application and view the result.