qwedster 0 Newbie Poster

Hi!

I am using Zedgraph in my ASP.NET application. I get a duplicate legend in my graph. How to remove? Please help!


Here's my code:

//Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Drawing;
using ZedGraph;
using System.Configuration;
using System.Data;
// using System.Data.SQLite;


public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            
            this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph1);

         
            if (!IsPostBack)
            {
                lblDateTime.Text = DateTime.Now.ToString();

                string SQLiteQuery = "SELECT BatteryName FROM Battery";

                DatabaseConnection ConnectionDatabase = new DatabaseConnection();
                DataSet DatSet = ConnectionDatabase.GetDataSet(SQLiteQuery);

                DataTable DatTable = DatSet.Tables[0];

                if (DatTable.Rows[0].IsNull(0) == false)
                {
                    lblBattery.Text = Convert.ToString(DatSet.Tables[0].Rows[0][0]);
                }
            }
        }
        catch (Exception ex)
        {
            string Error = ex.ToString();
        } 
    }

    List<double> XList;
    List<double> YList;

    private PointPairList GetPointPairList()
    {
        PointPairList list = new PointPairList();

        try
        {
              //string SQLiteQuery = "SELECT bp.PowerTime As DateTime, bp.PowerValue As Power ";
            //SQLiteQuery += "FROM BatteryPower bp ";
            //SQLiteQuery += "ORDER BY bp.PowerTime DESC;";

            //DatabaseConnection ConnectionDatabase = new DatabaseConnection();
            //DataSet DatSet = ConnectionDatabase.GetDataSet(SQLiteQuery);
     
            //DataTable DatTable = DatSet.Tables[0];

            //double x = 0.0D;
            //double y = 0.0D;

            //DateTime dt = new DateTime();

            
            //for (int i = 0; i < DatTable.Rows.Count; i++)
            //{
            //    if (DatTable.Rows[i].IsNull(0) == false && DatTable.Rows[i].IsNull(1) == false)
            //    {
            //        dt = DateTime.Parse(DatTable.Rows[i][0].ToString());
            //        x = (double)new XDate(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
            //        y = double.Parse(DatTable.Rows[i][1].ToString());
            //        list.Add(x, y);
            //    }
            //}

          
            // Hard-Coded Data:

            list.Add(39916.5291666668, 9.1243);  // 4/13/2009 12:42:00 PM
            list.Add(39916.5270833331, 10.1243); // 4/13/2009 12:39:00 PM
            list.Add(39916.5249999999, 10.3243); // 4/13/2009 12:36:00 PM
            list.Add(39916.5229166667, 10.8243); // 4/13/2009 12:33:00 PM
            list.Add(39916.5208333335, 11.8243); // 4/13/2009 12:30:00 PM
            list.Add(39916.5187499998, 12.8243); // 4/13/2009 12:27:00 PM
            list.Add(39916.5166666666, 13.8243); // 4/13/2009 12:24:00 PM
            list.Add(39916.5145833334, 11.8443); // 4/13/2009 12:21:00 PM
            list.Add(39916.5125000002, 11.4443); // 4/13/2009 12:18:00 PM
            list.Add(39916.5104166665, 13.4443); // 4/13/2009 12:15:00 PM
            list.Add(39916.5083333333, 11.4444); // 4/13/2009 12:12:00 PM
            list.Add(39916.5062500001, 13.4444); // 4/13/2009 12:09:00 PM
            list.Add(39916.5041666669, 12.4444); // 4/13/2009 12:06:00 PM


        }
        catch (Exception ex)
        {
            string Error = ex.ToString();
        }
        return list;
    }

    private void OnRenderGraph1(ZedGraph.Web.ZedGraphWeb z, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
    {
        try
        {
            GraphPane myPane = masterPane[0];

            myPane.ZoomStack.Capacity = 6;

            myPane.XAxis.MajorGrid.IsVisible = true;
            myPane.YAxis.MajorGrid.IsVisible = true;

            myPane.XAxis.MinorGrid.IsVisible  = false;
            myPane.YAxis.MinorGrid.IsVisible = false;

            myPane.XAxis.MajorTic.IsOutside = false;
            myPane.XAxis.MinorTic.IsOutside = false;
            myPane.XAxis.MinorTic.IsInside = false;
            myPane.XAxis.MinorTic.IsOpposite = false;

            myPane.YAxis.MajorTic.IsOutside = false;
            myPane.YAxis.MinorTic.IsOutside = false;
            myPane.YAxis.MinorTic.IsInside = false;
            myPane.YAxis.MinorTic.IsOpposite = false;

            myPane.XAxis.MajorGrid.DashOff = 0;
            myPane.XAxis.MajorTic.Color = Color.WhiteSmoke;

            myPane.YAxis.MajorGrid.DashOff = 0;
            myPane.YAxis.MajorTic.Color = Color.WhiteSmoke;

            myPane.XAxis.MajorGrid.Color = Color.WhiteSmoke;
            myPane.YAxis.MajorGrid.Color = Color.WhiteSmoke;


            string str = string.Empty;

           

            LineItem myCurve = myPane.AddCurve("Power Level", GetPointPairList(), Color.Goldenrod, SymbolType.Circle);


            myPane.XAxis.Type = AxisType.Date;

            //System.Drawing.Image image = System.Drawing.Image.FromFile(stringImageRoot);
            //myCurve.Symbol.Size = 18;
            //myCurve.Symbol.Border.IsVisible = false;
            //myCurve.Symbol.Fill = new Fill(image, WrapMode.Clamp);

            myCurve.Line.Width = 3.0F;

            myCurve.Symbol.Fill = new Fill(Color.White);

            XList.Sort();
            myPane.XAxis.Scale.Min = XList[0];
            myPane.XAxis.Scale.Max = XList[XList.Count - 1];

            YList.Sort();
            
            myPane.YAxis.Scale.Min = YList[0];
            myPane.YAxis.Scale.Max = YList[YList.Count - 1];


            if (SliderVertical.Text.Trim() != null)
            {
               myPane.XAxis.Scale.MajorStep = double.Parse(SliderVertical.Text);

                //myPane.XAxis.Scale.Max = XList[int.Parse(SliderVertical.Text)];
                //myPane.YAxis.Scale.Max = YList[int.Parse(SliderVertical.Text)];
            }
                    
            myPane.AxisChange(g);
         
        }
        catch (Exception ex)
        {
            string Error = ex.ToString();
        }
    }

    protected void SliderVertical_TextChanged(object sender, EventArgs e)
    {
        TextBox1.Text = SliderVertical.Text + " minutes";


        this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph1);

        IsLegend = true;
    }

}

// Defalut.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<%@ Register assembly="ZedGraph.Web" namespace="ZedGraph.Web" tagprefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>MSC Battery</title>
    <link href="css/battery_level_power_graph.css" type="text/css" rel="stylesheet" id="Link1" />
    <link href="css/slider.css" type="text/css" rel="stylesheet" id="Link2" />
</head>
<body>
    <form id="form1" runat="server">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />     
         
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                    <div>
                    
        <table>
            <tr>
                <td>
                <strong>Battery</strong>:
                <asp:Label ID="lblBattery" runat="server"></asp:Label>
                </td>
                <td>
                <strong>Date/Time</strong>:
                <asp:Label ID="lblDateTime" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
        
        <table>
            <tr>
                <td >                      
                
                    
                        <cc1:ZedGraphWeb ID="ZedGraphWeb1" runat="server" BaseDimension="8" Height="346"
                            Width="740">
                            
                            <XAxis AxisColor="Black" Cross="0" CrossAuto="true" IsOmitMag="false" IsPreventLabelOverlap="true"
                                IsShowTitle="true" IsTicsBetweenLabels="true" IsUseTenPower="false" IsVisible="true"
                                IsZeroLine="false" MinSpace="0" Title="" Type="Linear">
                                <FontSpec Angle="0" Family="Arial" FontColor="Black" IsBold="true" IsItalic="false"
                                    IsUnderline="false" Size="14" StringAlignment="Center">
                                    <Border Color="Black" InflateFactor="0" IsVisible="false" Width="1" />
                                    <Fill AlignH="Center" AlignV="Center" Color="White" ColorOpacity="100" IsScaled="true"
                                        IsVisible="true" RangeMax="0" RangeMin="0" Type="None" />
                                </FontSpec>
                                <MinorGrid Color="WhiteSmoke" IsVisible="false" />
                                <MajorGrid Color="WhiteSmoke" DashOff="0" IsVisible="true" PenWidth="1" />
                                <MinorTic Color="WhiteSmoke" IsInside="false" IsOpposite="false" IsOutside="false"
                                    PenWidth="0" Size="0" />
                                <MajorTic Color="WhiteSmoke" IsInside="false" IsOpposite="false" IsOutside="false"
                                    PenWidth="0" Size="0" />
                                <Scale Align="Center" Format="g" FormatAuto="true" IsReverse="false" Mag="0" MagAuto="true"
                                    MajorStep="5" MajorStepAuto="false" MajorUnit="Day" Max="0" MaxAuto="true" MaxGrace="0"
                                    Min="0" MinAuto="true" MinGrace="0" MinorStep="0" MinorStepAuto="true" MinorUnit="Day">
                                    <FontSpec Angle="0" Family="Arial" FontColor="Black" IsBold="false" IsItalic="false"
                                        IsUnderline="false" Size="14" StringAlignment="Center">
                                        <Border Color="Black" InflateFactor="0" IsVisible="false" Width="1" />
                                        <Fill AlignH="Center" AlignV="Center" Color="White" ColorOpacity="100" IsScaled="true"
                                            IsVisible="true" RangeMax="0" RangeMin="0" Type="None" />
                                    </FontSpec>
                                </Scale>
                            </XAxis> 
                                                        
                            <YAxis AxisColor="Black" Cross="0" CrossAuto="true" IsOmitMag="false" IsPreventLabelOverlap="true"
                                IsShowTitle="true" IsTicsBetweenLabels="true" IsUseTenPower="false" IsVisible="true"
                                IsZeroLine="true" MinSpace="0" Title="" Type="Linear">
                                <FontSpec Angle="-180" Family="Arial" FontColor="Black" IsBold="true" IsItalic="false"
                                    IsUnderline="false" Size="14" StringAlignment="Center">
                                    <Border Color="Black" InflateFactor="0" IsVisible="false" Width="1" />
                                    <Fill AlignH="Center" AlignV="Center" Color="White" ColorOpacity="100" IsScaled="true"
                                        IsVisible="true" RangeMax="0" RangeMin="0" Type="None" />
                                </FontSpec>
                                <MinorGrid Color="WhiteSmoke" IsVisible="false" />
                                <MajorGrid Color="WhiteSmoke" DashOff="0" IsVisible="true" PenWidth="1" />
                                <MinorTic Color="WhiteSmoke" IsInside="false" IsOpposite="false" IsOutside="false"
                                    PenWidth="0" Size="0" />
                                <MajorTic Color="WhiteSmoke" IsInside="false" IsOpposite="false" IsOutside="false"
                                    PenWidth="0" Size="0" />
                                <Scale Align="Center" Format="g" FormatAuto="true" IsReverse="false" Mag="0" MagAuto="true"
                                    MajorStep="1" MajorStepAuto="true" MajorUnit="Day" Max="0" MaxAuto="true" MaxGrace="2"
                                    Min="0" MinAuto="true" MinGrace="2" MinorStep="0" MinorStepAuto="true" MinorUnit="Day">
                                    <FontSpec Angle="90" Family="Arial" FontColor="Black" IsBold="false" IsItalic="false"
                                        IsUnderline="false" Size="14" StringAlignment="Center">
                                        <Border Color="Black" InflateFactor="0" IsVisible="false" Width="1" />
                                        <Fill AlignH="Center" AlignV="Center" Color="White" ColorOpacity="100" IsScaled="true"
                                            IsVisible="true" RangeMax="0" RangeMin="0" Type="None" />
                                    </FontSpec>
                                </Scale>
                            </YAxis>
                            
                            <Legend IsHStack="true" IsReverse="false" IsVisible="true"  Position="InsideTopRight">
                                <Location AlignH="Left" AlignV="Center" CoordinateFrame="ChartFraction" Height="0"
                                    Width="0" X="0" Y="0">
                                    <TopLeft X="0" Y="0" />
                                    <BottomRight X="0" Y="0" />
                                </Location>
                                <FontSpec Angle="0" Family="Arial" FontColor="Gray" IsBold="false" IsItalic="false"
                                    IsUnderline="false" Size="14" StringAlignment="Center">
                                    <Border Color="Black" InflateFactor="0" IsVisible="false" Width="1" />
                                    <Fill AlignH="Center" AlignV="Center" Color="Gray" ColorOpacity="0" IsScaled="true"
                                        IsVisible="true" RangeMax="0" RangeMin="0" Type="Solid" />
                                </FontSpec>
                                <Fill AlignH="Center" AlignV="Center" Color="Gray" ColorOpacity="0" IsScaled="true"
                                    IsVisible="true" RangeMax="0" RangeMin="0" Type="Solid" />
                                <Border Color="Gray" InflateFactor="0" IsVisible="false" Width="0" />
                            </Legend>
                            <PaneFill AlignH="Center" AlignV="Center" Color="#BEBEBE" ColorOpacity="100" IsScaled="true"
                                IsVisible="true" RangeMax="0" RangeMin="0" Type="Solid" />
                            <ChartFill AlignH="Center" AlignV="Center" Color="#BEBEBE" ColorOpacity="100" IsScaled="true"
                                IsVisible="true" RangeMax="0" RangeMin="0" Type="Solid" />
                            <ChartBorder Color="Gray" InflateFactor="0" IsVisible="true" Width="2" />
                            <MasterPaneBorder IsVisible="false" />
                            <Margins Bottom="5" Left="10" Right="0" Top="15" />
                            <PaneBorder IsVisible="false" />
                        </cc1:ZedGraphWeb>
                        
                
                </td>
                
                <td rowspan="2">

<html

                    <table>
                        <tr>
                            <td>
                            </td>
                        </tr>
                        <tr>
                            <td> 
                            <asp:TextBox ID="SliderVertical" runat="server" style="right:0px" Text="5" 
                               OnTextChanged="SliderVertical_TextChanged"  AutoPostBack="true"
                                Height="42px" Width="42px" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                            </td>
                        </tr>
                    </table>

                </td>
            </tr>
            <tr>
                <td>
                    <table>
                        <tr>
                            <td>
                            </td>
                            <td>
                            <asp:Label ID="lblDate" runat="server" style="text-align: center"></asp:Label> 
                                
                            <asp:TextBox ID="SliderHorizontal" runat="server" style="right:0px" Text="0"
                                Height="42px" Width="42px" />                        
                            </td>
                        </tr>
                    </table>

                </td>
            </tr>
        </table>
        
        <table>
            <tr>
                <td >
                
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
            </tr>
        </table>
        
        <table>
            <tr>
                <td>
                <a href="#" id="status_tab">Status</a>       
                </td>
                <td>
                 <a href="#" id="timeline_tab">Timeline</a>       
                </td>
                <td>
                 <a href="#" id="battery_level_power_report_tab">Power Report</a>       
                </td>
                <td>
                 <a href="battery_level_power_graph.aspx" id="battery_level_power_graph_tab">Power Graph</a>
                </td>
                <td>
                </td>
            </tr>
        </table>
        
       
                
       <ajaxToolkit:SliderExtender ID="SliderExtenderVertical" runat="server"             
            HandleImageUrl="images/slider_rail.gif"   
            RailCssClass="slider_v_rail"
            HandleCssClass="slider_v_handle"
            BehaviorID="SliderVertical"
            TargetControlID="SliderVertical"
            BoundControlID="SliderVertical_BoundControl"
            Orientation="Vertical" 
            EnableHandleAnimation="true"
            TooltipText="Slider: value {0}. Please slide to change value."
            Minimum="1"
            Maximum="5"
            Steps="5" />
            
        <ajaxToolkit:SliderExtender ID="SliderExtenderHorizontal" runat="server"
            HandleImageUrl="images/slider_rail.gif"             
            RailCssClass="slider_h_rail"
            HandleCssClass="slider_h_handle"
            BehaviorID="SliderHorizontal"
            TargetControlID="SliderHorizontal"
            BoundControlID="SliderHorizontal_BoundControl"
            Orientation="Horizontal"
            EnableHandleAnimation="true"
            TooltipText="Slider: value {0}. Please slide to change value." />             

            </div>
            </ContentTemplate>
                </asp:UpdatePanel> 
    </form>
</body>
</html>

// battery_level_power_graph.css

.T1
{
 width: 800px;
 height: 25px;
 border-style: solid;
 border-color: Black; 
 border-width: thin;
 margin-left: 230px; 
 margin-top: 0;
 padding-top: 0;
 padding: 0;
 border-collapse: collapse;
}

.T1C1
{
 width: 150px;
 height: 25px;    
    font-size: 14px;
 font-family: Tahoma;
    padding-left:15px;
}

.T1C2
{
 width: 650px;
 height: 25px;    
    font-size: 14px;
 font-family: Tahoma;
    padding-left:15px;
}
        
.T2
{
 width: 800px;
 height: 444px; 
 background-color: #BEBEBE;
 border-top-style: solid;
 border-top-color: Black;
 border-top-width: thin;
 border-bottom-style: solid;
 border-bottom-color: Black;
 border-bottom-width: thin;
 border-right-style: solid;
 border-right-color: Black;
 border-right-width: thin;
 border-left-style: solid;
 border-left-color: Black;
 border-left-width: thin;
 margin-left: 230px; 
 margin-top: 0;
 padding-top: 0;
 padding: 0;
 border-collapse: collapse; 
}

.T2C1
{
 width: 740px;
 height: 346px;
}

.T2C2
{
 width: 60px;
 height: 444px;
}

.T2C3
{
 width: 740px;
 height: 98px;
}

.T2C2NT1
{
 width: 50px;
 height: 444px;
 margin: 0;
 padding: 0;
 border-collapse: collapse;
}

.T2C2NT1C1
{
 width: 60px;
 height: 10px;
}

.T2C2NT1C2
{
 width: 60px;
 height: 390px;
}

.T2C2NT1C3
{
 width: 60px;
 height: 44px;
}

.T2C3NT2
{
 width: 740px;
 height: 98px;
 margin: 0;
 padding: 0;
 border-collapse: collapse;
}

.T2C3NT2C1
{
 width: 20px;
 height: 98px;
}

.T2C3NT2C2
{
 width: 720px;
 height: 98px;
    text-align: center; 
}

.T3
{
 width: 800px;
 height: 80px; 
 border-top-style: solid;
 border-top-color: Black;
 border-top-width: thin;
 border-bottom-style: solid;
 border-bottom-color: Black;
 border-bottom-width: thin;
 border-right-style: solid;
 border-right-color: Black;
 border-right-width: thin;
 border-left-style: solid;
 border-left-color: Black;
 border-left-width: thin;
 margin-left: 230px; 
 margin-top: 0;
 padding-top: 0;
 padding: 0;
 border-collapse: collapse;
}

.T4
{
 width: 800px;
 height: 42px;
 border-top-style: solid;
 border-top-color: Black;
 border-top-width: thin;
 border-bottom-style: solid;
 border-bottom-color: Black;
 border-bottom-width: thin;
 border-right-style: solid;
 border-right-color: Black;
 border-right-width: thin;
 border-left-style: solid;
 border-left-color: Black;
 border-left-width: thin;
 margin-left: 230px; 
 margin-top: 0;
 padding-top: 0;
 padding: 0;
 border-collapse: collapse;
}

.T4C1
{
 width: 65px;
 height: 42px;
 margin: 0;
 padding: 0;
 background-color: Black;
 border-right-style: solid;
 border-right-color: White;
 border-right-width: thin;
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C1Text
{
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}


.T4C2
{
 width: 82px;
 height: 42px; 
 margin: 0;
 padding: 0;
 background-color: Black;
 border-right-style: solid;
 border-right-color: White;
 border-right-width: thin;
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C2Text
{
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C3
{
 width: 114px;
 height: 42px; 
 margin: 0;
 padding: 0;
 background-color: Black;
 border-right-style: solid;
 border-right-color: White;
 border-right-width: thin;
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C3Text
{
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C4
{
 width: 114px;
 height: 42px; 
 margin: 0;
 padding: 0;
 background-color: Black;
 border-right-style: solid;
 border-right-color: White;
 border-right-width: thin;
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C4Text
{
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C5
{
 width: 425px;
 height: 42px; 
 margin: 0;
 padding: 0;
 background-color: Black;
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

.T4C5Text
{
 color: White; 
 text-align: center;
 text-decoration: none;
 font-size: 14px;
 font-weight: normal;
 font-family: Arial; 
}

 

// slider.css

.slider_h_rail 
{    
 position:relative;    
 height:42px;    
 width:698px; 
 background-color:White;
 border-style:solid;
 border-color:Black;
 border-width:thin;
}

.slider_h_handle 
{    
 position:absolute;    
 height:42px;    
 width:42px;
}

.slider_v_rail 
{    
 position:relative;    
 height:390px;    
 width:42px;    
 background-color:White;
 border-style:solid;
 border-color:Black;
 border-width:thin;
}

.slider_v_handle 
{    
 position:absolute;    
 height:42px;    
 width: 42px;
}