如何将SQL查询结果放入ASP.NET图表? [英] How to put SQL query result into a ASP.NET charts?
问题描述
我正在使用asp.net,c#在Web门户上工作。我是图表控件的新手。我有一个下面的SQL查询及其结果。如何将其放入饼图?
选择A,B,C,(A + B + C)作为总计FROM [dbo]。 [TestData]
ABC总计
40 10 50 100
我尝试了什么:
尝试使用SQL查询进行链接,但它有4个列。不知道怎么连接。
你好;
确定你的proyect之后web.config文件有正确的条目,看看这个例子(内容页面{.aspx}):
<%@ Register Assembly =System.Web。 DataVisualization,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35Namespace =System.Web.UI.DataVisualization.ChartingTagPrefix =asp%>
...
< asp:Chart ID =PieChart1runat =serverWidth =365px> <% - OnCustomizeLegend = PieChart1_CustomizeLegend - %GT;
< Series>
< asp:Series Name =Series1ChartType =PieYValueMembers =MarketShareXValueMember =recIdCesionarioXAxisType =PrimaryIsValueShownAsLabel =TrueLegend =CesionariosCustomProperties =PieLabelStyle = Outside LabelFormat ={P}Palette =SemiTransparent>< / asp:Series>
< / Series>
< ChartAreas>
< asp:ChartArea Name =ChartArea1Area3DStyle-Enable3D =true>
< Area3DStyle Enable3D =True倾斜=35旋转=15>< / Area3DStyle>
< / asp:ChartArea>
< / ChartAreas>
< Legends>
< asp:Legend Name =CesionariosTitle =CesionariosLegendStyle =ColumnLegendItemOrder =SameAsSeriesOrder>< / asp:Legend>
< / Legends>
< / asp:Chart>密切关注SERIES设置,因为有关键可以使它工作。
这是后面的代码(摘录):
private void LoadCharts(string SearchKey)
{
PieChart1.DataSource = DBCore.Get_MarketShareData(SearchKey);
PieChart1.DataBind();
}
希望这会有所帮助。
干杯!
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.
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!.
这篇关于如何将SQL查询结果放入ASP.NET图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!