1
votes

Consider a pie chart using the ASP.NET charting controls.

The requirement is around controlling the text that's rendered on the pie chart. The goal is to limit the number of characters on the label. The chart currently is bound to a SqlDataSource.

alt text http://www.imagechicken.com/uploads/1250716996036841800.png

<asp:Chart ID="myPieChart" runat="server" DataSourceID="myDS">
  <Series>
      <asp:Series ChartArea="myChartArea" Name="Series1" ChartType="Pie" 
                  XValueType="Int32" XValueMember="SomeName" 
                  YValueMembers="SomeNumber">
      </asp:Series>
 </Series>
 <ChartAreas>
     <asp:ChartArea Name="myChartArea">
       <AxisY Title="Number"></AxisY>
       <AxisX Title="Name"></AxisX>
       <Area3DStyle Enable3D="True" Inclination="20" />
     </asp:ChartArea>
 </ChartAreas>
</asp:Chart>

Question How would you specify, either in the <asp:Chart> markup, or in code-behind, to limit the number of characters that are bound/rendered to the pie chart?

3

3 Answers

1
votes

Do it at the database layer in your SQL statement. If characters exceed a certain length (e.g. 15), return just first 15 characters.

0
votes

You can do this by limiting the number of characters entered into the data source.

OR

In your SQL Procedure, you can add ellipses (or something to that effect) after a certain number of characters

0
votes

I was hoping for a solution that would be specific to the ASP.NET charting controls.

Seeing no clear answer for the charting controls, it was time to move to the source data. I was hesitant to substring the names from the columns to a custom length because that sproc was being reused/consumed by other form elements on other pages - a gridview.

The solution was to create a NEW COLUMN called DisplayName on the resultset in the stored proc. Instead of modifying the existing, I simply included a new column:

SELECT
SomeName 
,COUNT(SomeName) AS SomeNumber
,SUBSTRING(SomeName,0,15) AS DisplayName

This isn't an expensive solution in terms of development, research, time, and processing cost, so it's a win. Most times the presentation tier should take care of these issues, but in this case, the faster solution works when there isn't a clear solution at the presentation tier.

Thanks to Russ and waqasahmed!