Join and Chart

TatukGIS Internet Server Samples


Source code

This TatukGIS Internet Server sample demonstrates how to join the map to a database in order to present values from the database as pie/bar charts on the map. This join operation is to a Microsoft Access database file, but the sample is also applicable to joining to SQL server database products. This sample is a replica of the DK-ActiveX JoinAndChart sample which is found in the DK Sample Set #2. The ASP.NET source code for this sample is provided below.

A reference to the ADODB interop library is required. The ADODB interop library is found in the Microsoft .NET SDK. Place the ADODB.DLL in the BIN Directory.

Select one of the options (such as population, forest area, etc.) in the first drop down menu to render the sizes of the pie or bar charts based on the values from the database for the selected item. Select one of the options in the second drop down menu to color-render the charts to reflect the values of two types of data. The first option in the drop down menu represents the total population values with red color and the metropolitan population values with green color. The second option renders the land areas used for agriculture wth red color and the land areas used for forestry with green colors. The third drop down menu allows the user to select between the use of pie or bar charts.


JoinAndChart.aspx    Top

                            
                            
<%@ Page Language="VB" Debug="True" %>
<%@ Register TagPrefix="ttkGIS" Namespace="TatukGIS.IS" Assembly="TatukGIS.IS" %>
<%@ Import Namespace="ADODB" %>

<script runat="server">


    Dim GisUtils As API.XGIS_Utils
    Dim ParamsUtils As API.XGIS_ParamsUtils
    Dim ll As API.XGIS_LayerShp

    Sub GIS_FullExtent_Click(sender As Object, e As ImageClickEventArgs)
        GIS.FullExtent
    End Sub
    
    Sub GIS_ZoomIn_Click(sender As Object, e As ImageClickEventArgs)
        GIS.ZoomIn
    End Sub
    
    Sub GIS_ZoomOut_Click(sender As Object, e As ImageClickEventArgs)
        GIS.ZoomOut
    End Sub
    
    Sub GIS_Smaller_Click(sender As Object, e As ImageClickEventArgs)
        GIS.Width  = Unit.Pixel( GIS.Width.Value  - 54 )
        GIS.Height = Unit.Pixel( GIS.Height.Value - 40 )
    End Sub
    
    Sub GIS_Larger_Click(sender As Object, e As ImageClickEventArgs)
        GIS.Width  = Unit.Pixel( GIS.Width.Value  + 54 )
        GIS.Height = Unit.Pixel( GIS.Height.Value + 40 )
    End Sub
    
    
    Sub GIS_Load(sender As Object, e As EventArgs)
        GisUtils = New API.XGIS_Utils
        ParamsUtils = New API.XGIS_ParamsUtils
           
        'add some layers
        ll = New API.XGIS_LayerShp
        ll.Path = GisUtils.GisSamplesDataDir + "district.shp"
        ll.Name = "district"

        ll.UseConfig = False
        ll.Params.Labels.Field ="name"
        ll.Params.Labels.Pattern = API.XBrushStyle.XbsClear
        ll.Params.Labels.OutlineWidth = 0
        ll.Params.Labels.FontColor = RGB(0, 0, 0)
        ll.Params.Labels.Color = RGB(255, 255, 255)
        ll.Params.Labels.Position = API.XGIS_LabelPosition.XgisLabelPositionMiddleCenter
        ll.Params.Chart.Size = -&HFFFFFFF
        ll.Params.Render.StartSize = 350
        ll.Params.Render.EndSize = 1000

        GIS.API.Add(ll)
        GIS.FullExtent()
        GIS.ImageType = XgisImageType.PNG24
    End Sub


    Sub GIS_Paint(sender As Object, e As PaintEventArgs)
        Dim sqlDC as ADODB.Connection
        Dim sqlRS as ADODB.Recordset

        Dim vsize As String
        Dim vvalues As String
        Dim vstyle As String
        Dim vmin As Double
        Dim vmax As Double

        vsize = ddl_Size.Items(ddl_Size.SelectedIndex).Text
        vvalues = ddl_Values.Items(ddl_Values.SelectedIndex).Text
        vstyle = ddl_Style.Items(ddl_Style.SelectedIndex).Text

        sqlDC = new ADODB.Connection()
        sqlDC.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & GisUtils.GisSamplesDataDir & "district.mdb")

        sqlRS = new ADODB.Recordset()

        sqlRS.Open("SELECT min( " & vsize & ") AS mini, max(" & vsize & ") AS maxi FROM TDistrict", sqlDC)
        vmin = sqlRS.Fields("mini").Value
        vmax = sqlRS.Fields("maxi").Value
        sqlRS.Close()

        sqlRS.Open("select * FROM TDistrict  ORDER BY id", sqlDC)

        ll.JoinADO = sqlRS
        ll.JoinPrimary = "zone"
        ll.JoinForeign = "id"

        ll.Params.Render.Expression = vsize
        ll.Params.Render.Chart = "0:0:" & vvalues
        ll.Params.Chart.Style = ParamsUtils.ParamChart(vstyle, API.XGIS_ChartStyle.XgisChartStylePie)
        ll.Params.Render.Zones = 10
        ll.Params.Render.MinVal = vmin
        ll.Params.Render.MaxVal = vmax

        Gis.Draw()
    End Sub
    

</script>
<html>
<head>
    <title>TatukGIS Internet Server Samples</title>
    <link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <a name="top"> 
    <h1>Join and Chart
    </h1>
    <h2 class="comment"><a href="../../samplesAPI.htm">TatukGIS Internet Server Samples</a>
    </h2>
    <form runat="server">
        <p>
            <br />
        </p>
        <table style="WIDTH: 237px; HEIGHT: 204px" cellspacing="0" cellpadding="0" border="0">
            <tbody>
                <tr>
                    <td>
                        <asp:ImageButton id="GIS_FullExtent" onclick="GIS_FullExtent_Click" runat="server" ImageUrl="/TatukGIS_IS8/img/fullextent.gif"></asp:ImageButton>
                        <asp:ImageButton id="GIS_ZoomIn" onclick="GIS_ZoomIn_Click" runat="server" ImageUrl="/TatukGIS_IS8/img/zoomin.gif"></asp:ImageButton>
                        <asp:ImageButton id="GIS_ZoomOut" onclick="GIS_ZoomOut_Click" runat="server" ImageUrl="/TatukGIS_IS8/img/zoomout.gif"></asp:ImageButton>
                    </td>
                    <td align="right">
                        <asp:ImageButton id="GIS_Smaller" onclick="GIS_Smaller_Click" runat="server" ImageUrl="/TatukGIS_IS8/img/smaller.gif"></asp:ImageButton>
                        <asp:ImageButton id="GIS_Larger" onclick="GIS_Larger_Click" runat="server" ImageUrl="/TatukGIS_IS8/img/larger.gif"></asp:ImageButton>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <p>
                            <ttkGIS:XGIS_VIEWERIS id="GIS" runat="server" Height="280px" Width="360px" OnLoad="GIS_Load" OnPaint="GIS_Paint" BorderColor="CornflowerBlue" BorderWidth="1px"></ttkGIS:XGIS_VIEWERIS>
                        </p>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:DropDownList id="ddl_Size" runat="server" AutoPostBack="True">
                            <asp:ListItem Value="1">population</asp:ListItem>
                            <asp:ListItem Value="2">population_city</asp:ListItem>
                            <asp:ListItem Value="3">agriculture</asp:ListItem>
                            <asp:ListItem Value="4">forest</asp:ListItem>
                        </asp:DropDownList>
                        <asp:DropDownList id="ddl_Values" runat="server" AutoPostBack="True">
                            <asp:ListItem Value="1">population:population_city</asp:ListItem>
                            <asp:ListItem Value="2">agriculture:forest</asp:ListItem>
                        </asp:DropDownList>
                        <asp:DropDownList width="60px" id="ddl_Style" runat="server" AutoPostBack="True">
                            <asp:ListItem Value="1">Pie</asp:ListItem>
                            <asp:ListItem Value="2">Bar</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
    </a>
</body>
</html>