• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

ASP.net C# + Chart Control - Server.HTMLDECODE Label

I have a simple Bar graph that is populated from database, the labels on the X Axis i want to use Server.HTMLDECODE so they display correctly, how can I do this ?
1 Solution
Robert SchuttSoftware EngineerCommented:
Maybe using the DataBound event. Here's an example page:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="EE_Q_28630178_WEB.Default" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

<script runat="server">

        protected void Page_Load(object sender, EventArgs e) {
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn("name", typeof(string)), new System.Data.DataColumn("count", typeof(int)) });
            dt.Rows.Add(new object[] { "Peter", 123 });
            dt.Rows.Add(new object[] { "Paul", 456 });
            dt.Rows.Add(new object[] { "M&aacute;ry", 789 });
            Chart1.DataSource = dt;
            Chart1.Series[0].XValueMember = "name";
            Chart1.Series[0].YValueMembers = "count";

        protected void Chart1_DataBound(object sender, EventArgs e) {
            Chart c1 = (Chart)sender;
            for (int s = 0; s < c1.Series.Count; s++) {
                for (int i = 0; i < c1.Series[s].Points.Count; i++) {
                    c1.Series[s].Points[i].AxisLabel = Server.HtmlDecode(c1.Series[s].Points[i].AxisLabel);


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> EE Q_28630178 </title>
    <form id="form1" runat="server">
        <asp:Chart ID="Chart1" runat="server" ImageStorageMode="UseImageLocation" OnDataBound="Chart1_DataBound">
                <asp:Series Name="Series1">
                <asp:ChartArea Name="ChartArea1">

Open in new window

dkilbyAuthor Commented:
Worked perfect - thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now