Monday, March 5, 2012

Code For Microsoft chart controls

 Source Page:
 <div align="center">
        <asp:Label ID="Label1" runat="server" Text="MicroSoft ASP.NET Chart Controls" Font-Bold="True"
            Font-Size="XX-Large" ForeColor="#660033">
        </asp:Label>
    </div>
    <div>
        <asp:Chart ID="Chart2" runat="server" DataSourceID="SqlDataSource1" BorderlineColor="Black"
            BorderlineDashStyle="Solid" BackColor="Brown"
            BackGradientStyle="TopBottom" BackSecondaryColor="White"
            Width="378px">
            <BorderSkin SkinStyle="Raised" />
            <Series>
                <asp:Series ChartType="Column" Name="Temperature"
                    CustomProperties="MaxPixelPointWidth=50" ShadowOffset="2"
                    IsValueShownAsLabel="True">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea2" Area3DStyle-Enable3D="true">
                    <AxisX Interval="1" Title="month">
                    </AxisX>
                    <AxisY Interval="10" Title="temp">
                    </AxisY>
                    <Area3DStyle Enable3D="True"></Area3DStyle>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:MicrosoftChartsConnectionString4 %>"
            SelectCommand="SELECT [month], [Id], [temp], [recordhigh] FROM [Princetontemp]">
        </asp:SqlDataSource>
        <asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" BorderlineColor="Black"
            BorderlineDashStyle="Solid" BackColor="#B6D6EC" BackGradientStyle="TopBottom"
            BackSecondaryColor="White" Width="404px">
            <BorderSkin SkinStyle="Raised" />
            <Series>
                <asp:Series ChartType="Line" Name="Temperature" XValueMember="month" YValueMembers="temp"
                    CustomProperties="MaxPixelPointWidth=50" ShadowOffset="1" IsValueShownAsLabel="True">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true">
                    <AxisX Interval="1" Title="month">
                    </AxisX>
                    <AxisY Interval="10" Title="temp">
                    </AxisY>
                    <Area3DStyle Enable3D="True"></Area3DStyle>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:Chart ID="Chart3" runat="server" DataSourceID="SqlDataSource1" BorderlineColor="Black"
            BorderlineDashStyle="Solid" BackColor="Chocolate" BackGradientStyle="TopBottom"
            BackSecondaryColor="White" Width="409px">
            <BorderSkin SkinStyle="Raised" />
            <Series>
                <asp:Series ChartType="Bar" Name="Temperature" CustomProperties="DrawingStyle=Cylinder,color=Red,
         MaxPixelPointWidth=50" ShadowOffset="2" IsValueShownAsLabel="True">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea3" Area3DStyle-Enable3D="true">
                    <AxisX Interval="1" Title="month">
                    </AxisX>
                    <AxisY Interval="10" Title="temp">
                    </AxisY>
                    <Area3DStyle Enable3D="True"></Area3DStyle>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MicrosoftChartsConnectionString %>"
            SelectCommand="SELECT [Id], [month], [temp], [recordhigh] FROM [Princetontemp]">
        </asp:SqlDataSource>
        <asp:Chart ID="Chart4" runat="server" DataSourceID="SqlDataSource1" BorderlineColor="Black"
            BorderlineDashStyle="Solid" BackColor="Gold" BackGradientStyle="TopBottom" BackSecondaryColor="White"
            IsMapAreaAttributesEncoded="True" Height="322px" Width="443px">
            <BorderSkin SkinStyle="Raised" />
            <Legends>
                <asp:Legend AutoFitMinFontSize="6" Name="Legend1" Title="Months">
                </asp:Legend>
            </Legends>
            <Series>
                <asp:Series ChartType="Pie" Name="Temperature" XValueMember="month" YValueMembers="temp"
                    Legend="Legend1" CustomProperties="MaxPixelPointWidth=50" ShadowOffset="2" IsValueShownAsLabel="True">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea4" Area3DStyle-Enable3D="True">
                    <AxisX Interval="1">
                    </AxisX>
                    <AxisY Interval="10">
                    </AxisY>
                    <Area3DStyle Enable3D="True"></Area3DStyle>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:Chart ID="Chart6" runat="server" DataSourceID="SqlDataSource1" BorderlineColor="Black"
            BorderlineDashStyle="Solid" BackColor="DarkGray" BackGradientStyle="TopBottom"
            BackSecondaryColor="White" Width="401px">
            <BorderSkin SkinStyle="Raised" />
            <Series>
                <asp:Series ChartType="Bubble" Name="Temperature" XValueMember="month" YValueMembers="temp"
                    CustomProperties="MaxPixelPointWidth=25" ShadowOffset="2" IsValueShownAsLabel="True">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea6" Area3DStyle-Enable3D="true">
                    <AxisX Interval="1" Title="month">
                    </AxisX>
                    <AxisY Interval="10" Title="temp">
                    </AxisY>
                    <Area3DStyle Enable3D="True"></Area3DStyle>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:Chart ID="Chart5" runat="server" DataSourceID="SqlDataSource1" BorderlineColor="Black"
            IsMapAreaAttributesEncoded="True" BorderlineDashStyle="Solid" BackColor="Coral"
            BackGradientStyle="Center" BackSecondaryColor="White" Width="410px">
            <BorderSkin SkinStyle="Raised" />
            <Legends>
                <asp:Legend AutoFitMinFontSize="6" Name="Legend1" Title="Months">
                </asp:Legend>
            </Legends>
            <Series>
                <asp:Series ChartType="Pyramid" Name="Temperature" XValueMember="month" YValueMembers="temp"
                    IsValueShownAsLabel="True" Legend="Legend1" CustomProperties="MaxPixelPointWidth=50"
                    ShadowOffset="2">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea5" Area3DStyle-Enable3D="true">
                    <AxisX Interval="1" Title="month">
                    </AxisX>
                    <AxisY Interval="10" Title="temp">
                    </AxisY>
                    <Area3DStyle Enable3D="True"></Area3DStyle>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:Chart ID="Chart7" runat="server" DataSourceID="SqlDataSource1" BorderlineColor="Black"
            BorderlineDashStyle="Solid" BackColor="DeepSkyBlue" BackGradientStyle="None"
            BackSecondaryColor="White" Width="387px">
            <BorderSkin SkinStyle="Raised" />
            <Series>
                <asp:Series ChartType="Radar" Name="Temperature" XValueMember="month" YValueMembers="temp"
                    CustomProperties="DrawingStyle=Cylinder,MaxPixelPointWidth=100" ShadowOffset="4" IsValueShownAsLabel="True">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea7" Area3DStyle-Enable3D="true">
                    <AxisX Interval="1">
                    </AxisX>
                    <AxisY Interval="10">
                    </AxisY>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
    </div>

Code in Aspx.cs:
pageload:
 private void LoadChartData()
    {
        string constr = @"Server=USER9-PC; Database=MicrosoftCharts; user id=sa; password=secure2011";
        string query = "SELECT month,temp from Princetontemp";
        SqlDataAdapter da = new SqlDataAdapter(query, constr);
        DataTable table = new DataTable();       
        da.Fill(table);
        DataView dv = table.DefaultView;
       Chart1.Series["Temperature"].Points.DataBindXY(dv,"temp",dv,"month");
    }

No comments:

Post a Comment