• 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 ?
0
dkilby
Asked:
dkilby
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=4.0.0.0, 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";
            Chart1.DataBind();
        }

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

</script>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Chart ID="Chart1" runat="server" ImageStorageMode="UseImageLocation" OnDataBound="Chart1_DataBound">
            <Series>
                <asp:Series Name="Series1">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
    </div>
    </form>
</body>
</html>

Open in new window

capture
0
 
dkilbyAuthor Commented:
Worked perfect - thank you
0
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