locked
displaying different values in legend and pie chart RRS feed

  • Question

  • Hi All,

    I have the follwing code for my pie chart.

    In the code below, I want to display C2, c3, C4 in my legend along with the yvalue so for e.g. if the yValue[0] is 20% and yValue[1]= 60% and yValue[2]=20% then I want to display

    C2 20%

    C3 60%

    C4 20%

    Total 100%

    in my legend

    and in my pie chart, I want to display 20%, 60% and 20% in each seperation of the pie, I don't want to display C2, C3 and C4 in my pie chart.

    How can I acheive this.

    private void Bind_cRepSeverityChart(List<Metrics> metricList)
    {
    double[] yValue = new double[3];
    string[] xValues = { "C2", "C3", "C4" };
    for (int i = 0; i <= metricList.Count - 1; i++)
    {
    yValue[0] = double.Parse(metricList[0].C2c.ToString());
    yValue[1] = double.Parse(metricList[0].C3c.ToString());
    yValue[2] = double.Parse(metricList[0].C4c.ToString());
    }
    chart_cSeverity.Series["Series1"].Points.DataBindXY(xValues, yValue);
    chart_cSeverity.Series["Series1"].ChartType = SeriesChartType.Pie;
    chart_cSeverity.Series["Series1"]["PieLabelStyle"] = "Other";
    // chart_cSeverity.Series["Series1"].Label = "#VALY #VALX";
    chart_cSeverity.Series["Series1"].Label = "#VALY" + "%" ;
    chart_cSeverity.Titles[0].Text = "c Severity Breakdown";
    chart_cSeverity.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
    chart_cSeverity.Legends[0].Enabled = true;
    }
    


    and my pie chart code is like this.

    <asp:Chart ID="chart_cSeverity" runat="server">
    <Titles>
    <asp:Title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 14.25pt, style=Bold" ShadowOffset="3"
    Text="Pie Chart" Name="Title1" ForeColor="26, 59, 105">
    </asp:Title>
    </Titles>
    <Legends>
    <asp:Legend BackColor="Transparent" Alignment="Center" Docking="Bottom" Font="Trebuchet MS, 8.25pt, style=Bold"
    IsTextAutoFit="False" Name="Default" LegendStyle="Row">
    </asp:Legend>
    </Legends>
    <Series>
    <asp:Series Name="Series1" ChartType="Pie">
    </asp:Series>
    </Series>
    <ChartAreas>
    <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BackSecondaryColor="Transparent"
    BackColor="Transparent" ShadowColor="Transparent" BorderWidth="0">
    <Area3DStyle Rotation="0" />
    <AxisY LineColor="64, 64, 64, 64">
    <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
    <MajorGrid LineColor="64, 64, 64, 64" />
    </AxisY>
    <AxisX LineColor="64, 64, 64, 64">
    <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
    <MajorGrid LineColor="64, 64, 64, 64" />
    </AxisX>
    </asp:ChartArea>
    </ChartAreas>
    </asp:Chart>
    private void Bind_cRepSeverityChart(List<Metrics> metricList)
    {
    double[] yValue = new double[3];
    string[] xValues = { "C2", "C3", "C4" };
    for (int i = 0; i <= metricList.Count - 1; i++)
    {
    yValue[0] = double.Parse(metricList[0].C2c.ToString());
    yValue[1] = double.Parse(metricList[0].C3c.ToString());
    yValue[2] = double.Parse(metricList[0].C4c.ToString());
    }
    chart_cSeverity.Series["Series1"].Points.DataBindXY(xValues, yValue);
    chart_cSeverity.Series["Series1"].ChartType = SeriesChartType.Pie;
    chart_cSeverity.Series["Series1"]["PieLabelStyle"] = "Other";
    // chart_cSeverity.Series["Series1"].Label = "#VALY #VALX";
    chart_cSeverity.Series["Series1"].Label = "#VALY" + "%" ;
    chart_cSeverity.Titles[0].Text = "c Severity Breakdown";
    chart_cSeverity.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
    chart_cSeverity.Legends[0].Enabled = true;
    }

    any help will be greatly appreciated.


    vinki
    Monday, July 4, 2011 1:42 AM

All replies

  • Hi Vinki, I am sure you would've figured it out by now. In case not, here is how you do it by using the DataPoint's properties- The "LegendText" represents your text in the legend and the "Label" represents whats shown in the Pie. Make sure to change it for all data points in your chart and you would get it. Example: For a chart to Display "Images" in Legend and the "Percentage Value" (55%) in the Pie, you would set it like this-

    dataPoint1.LegendText = "Images";

    dataPoint1.Label = "#PERCENT";

    If you want the Label ("Images") as well with along with "Percentage" in the Pie, you should rather use

    dataPoint1.Label = ""#VALX (#PERCENT)"; //Which would give - Images (55%) - in the pie.

     

    Monday, October 24, 2011 1:18 PM
  • Hi Vinki, I am sure you would've figured it out by now. In case not, here is how you do it by using the DataPoint's properties- The "LegendText" represents your text in the legend and the "Label" represents whats shown in the Pie. Make sure to change it for all data points in your chart and you would get it. Example: For a chart to Display "Images" in Legend and the "Percentage Value" (55%) in the Pie, you would set it like this-

    dataPoint1.LegendText = "Images";

    dataPoint1.Label = "#PERCENT";

    If you want the Label ("Images") as well with along with "Percentage" in the Pie, you should rather use

    dataPoint1.Label = ""#VALX (#PERCENT)"; //Which would give - Images (55%) - in the pie.

     

    Beautiful thanks! I've been looking for how to do this forever!
    Friday, October 28, 2011 8:16 PM