locked
How to show value instead of percentage in Stackedcolumn100 chart in asp.net? RRS feed

  • Question

  • User660836111 posted

    I am working on charts in asp.net. In want to confirm, is it possible to show value instead of percentage in StckedColumn100 chart?

    HTML & code part is given below, Please suggest how to proceed. Your suggestion will be appreciated. Thanks in advance.

    Image of the required chart:

    Required

    My Out Put Image(with my Code): 

    HTML Part

    <asp:Chart ID="Chart3" runat="server" Width="700px" BackColor="#f2f2f2">
                            <Titles>
                                <asp:Title Font="Open Sans, 12pt, style=Bold" Name="Title1" Text="Observations submitted by administrator" />
                            </Titles>
                            <Series>
                                <asp:Series Name="Completed" IsValueShownAsLabel="true" LabelFormat="P2" ChartType="StackedColumn100" Color="#C39919"></asp:Series>
                                <asp:Series Name="InProgress" IsValueShownAsLabel="true" ChartType="StackedColumn100" Color="#D2D3D7"></asp:Series>
                            </Series>
                            <Legends>
                                <asp:Legend Alignment="Center" Docking="Top" IsTextAutoFit="true" Name="Yes" LegendStyle="Table" />
                            </Legends>
                            <ChartAreas>
                                <asp:ChartArea Name="ChartArea1">
                                    <AxisY>
                                        <MajorGrid Enabled="false" />
                                        <LabelStyle Format="" />
    
                                    </AxisY>
                                    <AxisX>
                                        <MajorGrid Enabled="False" />
                                    </AxisX>
                                </asp:ChartArea>
                            </ChartAreas>
                        </asp:Chart>



    Code to bind Chart: This is sample code to populate chart control with type StackedColumn100. unable to show exact value, as it is showing percentage on the basis of values. I want to show full stacked bar with original values as labels.
    
    
     DataTable tb = new DataTable();
    
            DataRow dr;
    
            tb.Columns.Add("Number1", typeof(string));
            tb.Columns.Add("Number2", typeof(string));
            tb.Columns.Add("RoleName", typeof(string));
            dr = tb.NewRow();
            dr["Number1"] = "42";
            dr["Number2"] = "0";
            dr["RoleName"] = "Teacher";
            tb.Rows.Add(dr);
            dr = tb.NewRow();
            dr["Number1"] = "22";
            dr["Number2"] = "5";
            dr["RoleName"] = "Paraprofessionals";
            tb.Rows.Add(dr);
    
    
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                Chart3.Series["Completed"].Points.Add(new DataPoint(i, tb.Rows[i]["Number1"].ToString().Trim()));
                Chart3.Series["InProgress"].Points.Add(new DataPoint(i, tb.Rows[i]["Number2"].ToString().Trim()));
                Chart3.Series["Completed"].LabelForeColor = System.Drawing.Color.Snow;
                Chart3.Series["InProgress"].LabelForeColor = System.Drawing.Color.Black;
                Chart3.Series["InProgress"].Points[i].AxisLabel = tb.Rows[i]["RoleName"].ToString().Trim();
                Chart3.Series["Completed"].Points[i].AxisLabel = tb.Rows[i]["RoleName"].ToString().Trim();
    
                Chart3.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled = false;
    
                Chart3.ChartAreas["ChartArea1"].AxisY.MajorTickMark.Enabled = false;
                Chart3.ChartAreas["ChartArea1"].AxisY.MinorTickMark.Enabled = false;
    
                Chart3.ChartAreas["ChartArea1"].AxisY.LineWidth = 0;
            }

    Monday, July 30, 2018 4:52 AM

Answers

  • User36583972 posted


    Hi aman_5631,

    am working on charts in asp.net. In want to confirm, is it possible to show value instead of percentage in StckedColumn100 chart?

    HTML & code part is given below, Please suggest how to proceed. Your suggestion will be appreciated. Thanks in advance.

    You can use the DataPointCustomProperties.Label to format a label for a datapoint in an asp.net chart.

    You could try setting IsValueShownAsLabel = True and modify the Label attribute as the follow.

         <Series>
                        <asp:Series Name="Completed" IsValueShownAsLabel="true" Label="#VALY{#.##}" ChartType="StackedColumn100" Color="#C39919"></asp:Series>
                        <asp:Series Name="InProgress" IsValueShownAsLabel="true" Label="#VALY{0.00}"  ChartType="StackedColumn100" Color="#D2D3D7"></asp:Series>
                    </Series>
    


    Keywords [rs_vsDataVis] : a keyword is a character sequence that is replaced with an automatically calculated value at run time.

    Custom numeric format strings
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 31, 2018 8:01 AM

All replies

  • User36583972 posted


    Hi aman_5631,

    am working on charts in asp.net. In want to confirm, is it possible to show value instead of percentage in StckedColumn100 chart?

    HTML & code part is given below, Please suggest how to proceed. Your suggestion will be appreciated. Thanks in advance.

    You can use the DataPointCustomProperties.Label to format a label for a datapoint in an asp.net chart.

    You could try setting IsValueShownAsLabel = True and modify the Label attribute as the follow.

         <Series>
                        <asp:Series Name="Completed" IsValueShownAsLabel="true" Label="#VALY{#.##}" ChartType="StackedColumn100" Color="#C39919"></asp:Series>
                        <asp:Series Name="InProgress" IsValueShownAsLabel="true" Label="#VALY{0.00}"  ChartType="StackedColumn100" Color="#D2D3D7"></asp:Series>
                    </Series>
    


    Keywords [rs_vsDataVis] : a keyword is a character sequence that is replaced with an automatically calculated value at run time.

    Custom numeric format strings
    https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 31, 2018 8:01 AM
  • User660836111 posted

    Hi Yong Lu,

    Issue was resolved, I have done this using code. But the idea was same as you have given. They way you have explained is very good. Thanks for response.

    Wednesday, September 12, 2018 9:15 AM