• 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];         }     }
    效果:

    
    
  • 相关阅读:
    python二维数组的创建
    使用js制作 下拉选择日期列表 (即日期选择器)
    onblur事件和onfocus事件失效
    jQuery中$("input")与$(":input")的区别
    jQuery之绑定焦点事件(焦点事件失效)
    django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on ‘127.0.0.1’)
    UCI机器学习数据库
    Cannot open the disk 'F:centos64-finalCentOS 64-bitCentOS 64-bit.vmdk' orone of the snapshot disk
    mr本地运行的几种模式
    序列化为XML
  • 原文地址:https://www.cnblogs.com/zhouhb/p/4241149.html
Copyright © 2020-2023  润新知