如何在ASP.NET中创建StackedColumn图表?

时间:2011-01-04 14:30:37

标签: c# asp.net charts stacked

我有一个数据集,我希望使用VS 2010中的内置图表呈现为堆积柱形图。数据看起来像这样,并从存储过程从SQL Server返回:

numTrades   Type    symbol
3   BreakEven   GBPCHF
7   Loss    GBPCHF
11  Win GBPCHF
1   BreakEven   GBPJPY
3   Loss    GBPJPY
7   Win GBPJPY
7   Loss    GBPUSD
13  Win GBPUSD

我用于呈现图表的ASP.Net代码如下所示:

<asp:Chart 
    ID="chtWinnerPercentagePie" 
    runat="server" 
    DataMember="DefaultView" 
    Height="600px" 
    Palette="Pastel" 
    Width="900px"  
    AlternateText="WinLoss Pie" 
    SkinID="chartSkin"
    ImageType="Png" >
   <Series >
      <asp:Series 
        Name="WinnersLosers" 
        ChartType="StackedColumn"
        ChartArea="MainChartArea" 
        XValueMember="symbol" 
        YValueMembers="numTrades">             
      </asp:Series>          
   </Series>       
   <Legends>
    <asp:Legend Name="Legend" ForeColor="#A1A5A9" BackColor="#161616" />
   </Legends>
   <ChartAreas>       
      <asp:ChartArea 
        Name="MainChartArea" 
        BackColor="#2C2C2C">
        <AxisY Title="Num Trades" TitleForeColor="White"> 
            <LabelStyle ForeColor="White" />                   
            <MajorGrid LineColor="#000000" />
        </AxisY>
        <AxisX Enabled="True">
            <LabelStyle ForeColor="White" />
        </AxisX>
      </asp:ChartArea>
   </ChartAreas>
    <Titles>
        <asp:Title 
            Name="ChartTitle" 
            Text="Win/Loss Ratio" 
            Font="Microsoft Sans Serif, 10pt" 
            ForeColor="#A1A5A9" 
            BackColor="#161616">
        </asp:Title>
    </Titles>
</asp:Chart> 

我没有得到堆积图表,当我加载页面时,我得到了这个: http://tinypic.com/r/66kljl/7

我哪里错了?

2 个答案:

答案 0 :(得分:1)

堆叠图表不需要多个系列吗?我相信你需要为你想要的东西创造三个。

答案 1 :(得分:1)

看看:

http://liberofusioncharts.codeplex.com/wikipage?title=Single%20Series%20Chart,%20adding%20data%20manually&referringTitle=Home

只需要更改c#代码中的第1行:

from:Column3DChart oChart = new Column3DChart();

to:StackedBar2DChart oChart = new StackedBar2DChart();

enter image description here