1
votes

I have a databound chart in ASP.NET C#. One of the databound fields is text and the other is a value. I would like the legend to display the text for the pie chart, and I would like the value to determine how the chart is formed, and also display as a label on each piece of the pie chart.

Here is the code I have so far:

      <asp:Chart ID="consignedChart" runat="server" DataSourceID="SqlDataSource4" 
                    BackColor="LightSlateGray" Palette="None" 
                    PaletteCustomColors="LightSeaGreen; SteelBlue" Width="400px" >
                    <Series>
                        <asp:Series Name="Series1" ChartType="Pie" XValueMember="Owner" 
                            YValueMembers="TotalValue" Legend="Legend1"  >
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                 <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true" BackColor="LightSlateGray">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic"/>
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend1">
                        </asp:Legend>
                    </Legends>
       </asp:Chart>

EDIT

Here is an image, it might make it easier to understand. The labels in the red boxes are the ones I want changed to display the value number.

chart

1

1 Answers

1
votes

I am aware this answer might come a little too late, please don't fry me for that :)

I'm not sure how you bind your data, but I downloaded and installed the Microsoft Chart for Windows Forms Samples Environment, and I could learn a lot from that.

Here is a link where you can get also asp.net samples from MSDN archives.

I am also using ILSpy to look at the code in the System.Windows.Forms.DataVisualization.Charting namespace. This way you can find about a lot of undocumented things.

Finally, here's some winform code sample from which you could draw some idea for your issue, and then write it in asp.net markup:

using System.Windows.Forms.DataVisualization.Charting;
...

// Show data points values as labels
chart1.Series["Series1"].IsValueShownAsLabel = true;

// Set axis label 
chart1.Series["Series1"].Points[2].AxisLabel = "My Axis Label\nLabel Line #2";

// Set data point label
chart1.Series["Series1"].Points[2].Label = "My Point Label\nLabel Line #2";

Hope that helps.