Legends:LegendItem item = new LegendItem();
            item.Name = name;
            item.Color = Color.Red;
            ser1.IsValueShownAsLabel = false;
            Chart2.Legends["Legend1"].CustomItems.Add(item);
            Chart2.Series.Add(ser1);我只定义了一个,为什么却显示2个,求解?

解决方案 »

  1.   

    是不是加了2次的原因
    Chart2.Legends["Legend1"].CustomItems.Add(item);
    Chart2.Series.Add(ser1);去掉一次
      

  2.   


    for (int ii = 0; ii < months.Count; ii++)
                    { int id = 100;
                        if (ddlTmHm.SelectedItem.Value == "0")
                        {
                            for (int iii = 0; iii < dt.Rows.Count; iii++)
                            {                            if (months[ii].ToString() == dt.Rows[iii]["collecttime"].ToString())
                                {
                                    id = iii;
                                    break;
                                }
                            }
                            DataPoint dp = new DataPoint(ii + 1, id == 100 ? "0" : dt.Rows[id]["temperature"].ToString());
                            dp.Label = id == 100 ? "0" : dt.Rows[id]["temperature"].ToString();                        if (!isCreate)
                            {
                                CustomLabel lbl = new CustomLabel();
                                lbl.FromPosition = ii + 0.5;
                                lbl.Text = months[ii].ToString();
                                lbl.ToPosition = ii + 1.5;
                                Chart2.ChartAreas[0].AxisX.CustomLabels.Add(lbl);
                            }
                            ser1.Points.Add(dp);
    }
    isCreate = true;
                LegendItem item = new LegendItem();
                item.Name = name;
                item.Color = Color.Red;
                ser1.IsValueShownAsLabel = false;
                Chart2.Legends["Legend1"].CustomItems.Add(item);
                Chart2.Series.Add(ser1);month=30
      

  3.   

    查询数据结果对应到Chart的XY轴1 1)  string strSql = "SELECT Top 5 empid, COUNT(*) AS lNum FROM log where empid <> '' GROUP BY empid ORDER BY empid";
     2   DataSet ds = SqlHelper.ExecuteDataset(strConnISPD, CommandType.Text, strSql);     
     3  DataView dv = new DataView(ds.Tables[0]);
     4  Chart1.Series["login"].Points.DataBindXY(dv, "empid", dv, "lNum");
     5  2) SqlCommand cd = new SqlCommand(strSql, conn);
     6     SqlDataAdapter da = new SqlDataAdapter();       
     7     da.SelectCommand = cd;
     8     DataSet ds = new DataSet();
     9    da.Fill(ds, "log");
    10    DataView dv = new DataView(ds.Tables[0]);
    11    dv.Sort="empid";
    12   Chart1.Series["login"].Points.DataBindXY(dv, "empid", dv, "lNum");使用现有数组数据到Chart的XY轴1 double[] yValues = {12, 67, 45, double.NaN, 67, 89, 35, 12, 78, 54}; 
    2  double[] xValues = {1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999};
    3 Chart1.Series["Series1"].Points.DataBindXY(xValues, yValues); 
      

  4.   


                <asp:Chart ID="Chart2" runat="server" Palette="BrightPastel" BackColor="#D3DFF0"
                    Width="900px" Height="360px" BorderDashStyle="Solid" BackGradientStyle="TopBottom"
                    BorderWidth="2" BorderColor="26, 59, 105" IsSoftShadows="False">
                    <Titles>
                        <asp:Title ShadowColor="32, 0, 0, 0" Font="楷体_GB2312, 14.25pt, style=Bold" ShadowOffset="3"
                            Text="***" Alignment="TopLeft" ForeColor="26, 59, 105" Name="Title1">
                            <Position Y="2" Height="8.738057" Width="80" X="20"></Position>
                        </asp:Title>
                    </Titles>
                    <Legends>
                        <asp:Legend LegendStyle="Row" IsTextAutoFit="false" Name="Legend1" BackColor="Transparent"
                            Font="楷体_GB2312, 9pt">
                            <CustomItems>
                            </CustomItems>
                            <Position Y="100" Height="12" Width="90" X="5"></Position>
                        </asp:Legend>
                    </Legends>
                    <Series>
                    </Series>
                    <BorderSkin SkinStyle="Emboss" />
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BackSecondaryColor="Transparent"
                            BackColor="Transparent" ShadowColor="Transparent" BackGradientStyle="TopBottom">
                            <AxisX LineColor="64, 64, 64, 64" IsLabelAutoFit="False" Interval="1">
                                <LabelStyle Font="Trebuchet MS, 8.25pt" Interval="1" IntervalOffset="Auto" IntervalOffsetType="Auto"
                                    IntervalType="Auto" />
                                <MajorGrid LineColor="64, 64, 64, 64" Interval="1" IntervalOffset="Auto" IntervalOffsetType="Auto"
                                    IntervalType="Auto" />
                                <CustomLabels>
                                </CustomLabels>
                                <MajorTickMark Interval="1" IntervalOffset="Auto" IntervalOffsetType="Auto" IntervalType="Auto" />
                            </AxisX>
                            <InnerPlotPosition Height="86.60734" Width="90.64261" X="9.35739" Y="3.5" />
                        </asp:ChartArea>
                    </ChartAreas>
                </asp:Chart>