zoukankan      html  css  js  c++  java
  • Chart控件使用初步

    学习了Chart控件的初步使用方法,生成柱形图和饼图。

       <asp:Chart ID="Chart1" runat="server" Width="553px" Height="403px">
                <Series>
                    <asp:Series LegendText="得票数" Name="Series1" IsValueShownAsLabel="True" XValueMember="选择项"
                        YValueMembers="数量" Legend="Legend1" Color="Red" Font="Microsoft Sans Serif, 12pt"
                        LabelForeColor="Green">
                    </asp:Series>
                    <asp:Series ChartArea="ChartArea2" ChartType="Pie" Legend="Legend2" 
                        Name="Series2" IsValueShownAsLabel="True" XValueMember="选择项"
                        YValueMembers="数量" XValueType="String">
                    </asp:Series>
                </Series>
                <ChartAreas>
                    <asp:ChartArea Name="ChartArea1">
                        <AxisY Title="得票数">
                            <LabelStyle ForeColor="Blue" />
                        </AxisY>
                        <AxisX Title="课程">
                            <MajorGrid LineColor="Yellow" />
                            <%--线条颜色--%>
                        </AxisX>
                    </asp:ChartArea>
                    <asp:ChartArea Name="ChartArea2">
                        <AxisY Title="得票数">
                            <LabelStyle ForeColor="Blue" />
                        </AxisY>
                        <AxisX Title="课程">
                            <MajorGrid LineColor="Yellow" />
                            <%--线条颜色--%>
                        </AxisX>
                    </asp:ChartArea>
                </ChartAreas>
                <Legends>
                    <asp:Legend Name="Legend1">
                    </asp:Legend>
                    <asp:Legend Name="Legend2">
                    <Position X="80" Y="50" Height="20" Width="30" />
                    </asp:Legend>
                </Legends>
                <Titles>
                    <asp:Title Name="Title1" Text="投票结果">
                    </asp:Title>
                </Titles>
            </asp:Chart>
    后台代码:
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
     
                    Chart1.DataSource = GetTable();
    //#XVAL表示数据点的X值,#YVAL表示数据点的Y值                 Chart1.Series[1].Label = "课程:#VALX,得票数:#VALY";
    //显示在饼图外面                 Chart1.Series[1].CustomProperties = "PieLabelStyle=Outside";                 Chart1.Series[1].LabelToolTip = "#VALX: #VALY";
    //自定义图例                 Chart1.Series[1].LegendText = "#VALX";                              }         }         public DataTable GetTable()         {             string collectionstring = @"Data Source=.sqlexpress;Initial Catalog=OnlineVoteDB;User ID=sa;Pwd=xx;Persist Security Info=True;";              SqlConnection conn = new SqlConnection(collectionstring);             SqlDataAdapter sad = new SqlDataAdapter("select name as 选择项,votecount as 数量 from [Items] where [SubjectID]=13 ", conn);             DataSet ds = new DataSet();             sad.Fill(ds, "table"); conn.Close();             return ds.Tables[0];         }     }
    效果:

    
    
  • 相关阅读:
    storage存储对象和数组类型时候的问题
    关于vue-router路径配置的问题
    解决v-for产生的警告的办法
    网页调用打印机打印文件
    vue-router的link样式设置问题
    在vue项目当中使用sass
    使用正则获取地址栏参数的方法
    escape、encodeURI和encodeURIComponent的区别
    SQLServer安装错误之--->无法打开项 UNKNOWNComponentsDA42BC89BF25F5BD0AF18C3B9B1A1EE8c1c4f01781cc94c4c8fb1542c0981a2a
    软件收集网站!
  • 原文地址:https://www.cnblogs.com/zhouhb/p/4241149.html
Copyright © 2011-2022 走看看