Click here to Skip to main content
14,161,172 members
Rate this:
Please Sign up or sign in to vote.
I am working on a web portal using, 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.
Updated 27-Nov-18 5:00am
Sk Imad 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 :

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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>


            <asp:Chart ID="PieChart1" runat="server" Width="365px">  <%--OnCustomizeLegend="PieChart1_CustomizeLegend"--%>
                    <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> 
                    <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true">
                        <Area3DStyle Enable3D="True" Inclination="35" Rotation="15"></Area3DStyle>
                    <asp:Legend Name="Cesionarios" Title="Cesionarios" LegendStyle="Column" LegendItemOrder="SameAsSeriesOrder"></asp:Legend>
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);


Hope this helps.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190518.1 | Last Updated 27 Nov 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100