Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I am working on a web portal using asp.net, c#. I am new to charts control. I have a below SQL query and its result. How to put this into a pie chart?

" SELECT A,B,C,(A+B+C) as Total FROM [dbo].[TestData] "


A B C Total
40 10 50 100

What I have tried:

Tried linking with SQL query but it is having 4 columns. not sure how to connect.
Posted
Updated 27-Nov-18 5:00am
Comments
[no name] 26-Nov-18 0:07am    
What exactly do you want? Which chart are you using? Can you show the source code?
Shashank Laxman 27-Nov-18 3:03am    
From Your Question you can keep ABC as X-axis and Total as Y-axis.
So your plotting points will be (40,100),(10,100),(50,100).

For Code :

https://www.aspsnippets.com/Articles/Create-ASPNet-Chart-Control-from-Database-using-C-and-VBNet-Example.aspx

Hope this helps.
Vipin_Arora 27-Nov-18 3:51am    
Name the chart you want to use. Also if you want Bar or pie charts, then logically total of all fields will not be part of pies/bars. However, Total would be shown separately.

1 solution

Hi there;

After you've made sure your proyect's web.config file has the proper entries, take a look at this example (Content Page {.aspx}):
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

...

            <asp:Chart ID="PieChart1" runat="server" Width="365px">  <%--OnCustomizeLegend="PieChart1_CustomizeLegend"--%>
                <Series> 
                    <asp:Series Name="Series1" ChartType="Pie" YValueMembers="MarketShare" XValueMember="recIdCesionario" XAxisType="Primary" IsValueShownAsLabel="True" Legend="Cesionarios" CustomProperties="PieLabelStyle=Outside" LabelFormat="{P}" Palette="SemiTransparent"></asp:Series> 
                </Series>
                <ChartAreas> 
                    <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true">
                        <Area3DStyle Enable3D="True" Inclination="35" Rotation="15"></Area3DStyle>
                    </asp:ChartArea>
                </ChartAreas>
                <Legends>
                    <asp:Legend Name="Cesionarios" Title="Cesionarios" LegendStyle="Column" LegendItemOrder="SameAsSeriesOrder"></asp:Legend>
                </Legends>
            </asp:Chart>
Pay close attention to the SERIES settings, for there's the key to make it work.

Here's the code behind (extract):
private void LoadCharts(string SearchKey)
{
    PieChart1.DataSource = DBCore.Get_MarketShareData(SearchKey);
    PieChart1.DataBind();

}

Hope this helps.

Cheers!.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900