在mschart中指定工具提示指向(ASP.net C#)

时间:2015-08-10 14:08:49

标签: c# asp.net charts mschart

我需要在将鼠标移动到数据点上时显示工具提示中的值。它显示的值显示在不正确的数据点中的值。 yvalue和axis lable collection是
 (237.71,12:13:58),  (238.53,12:28:58),  (239.95,12:58:58),  (238.25,1:13:57),  (240.17,1:29:01),  (241.24,1:58:57),
 (243.24,2:13:57),  (243.47,2:28:58),  (242.05,2:58:57),    例如,在移动鼠标超过237.71数据点时,它显示238.53。 并且在将鼠标移动到241.24数据点上时,它显示242.05。请提出任何建议。

Chart1.Visible = true;
    string startDate = "", EndDate = "";
    Chart1.BackColor = System.Drawing.Color.FromArgb(211, 223, 240); //"#D3DFF0"
    Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
    Chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
    Chart1.Legends.Add("R Phase");
    Chart1.Series.Add("R Phase");
    Chart1.Series[0].BorderColor = System.Drawing.Color.Transparent;
    Chart1.ChartAreas[0].AxisX.Title = "Time";
    Chart1.ChartAreas[0].AxisY.Title = "Value";
    Chart1.Series[0].ChartType = SeriesChartType.Line;
    Chart1.Series[0].BorderWidth = 3;
    Chart1.Series[0].Color = Color.Maroon;
    Chart1.Series[0].Points.DataBindXY(AxisLabelGrid1, yValueGrid1);
    Chart1.Series[0].IsValueShownAsLabel = true;
    Chart1.Series[0].IsVisibleInLegend = true;
    Chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Auto;
    Chart1.ChartAreas[0].AxisX.Interval = 1.0;
    //Chart1.Series[0].ToolTip = "#VALX - #VALY";
    int i = 0;
    foreach (var pt in Chart1.Series[0].Points)
    {
        string date = GridView1.Rows[i].Cells[0].Text;
       pt.ToolTip = "Value :" + GridView1.Rows[i].Cells[1].Text + "\n Phase : Y Phase";
        if (i == 0)
        {
            startDate = date;
        }
        EndDate = date;
        pt.MarkerColor = System.Drawing.Color.Maroon;
        pt.MarkerSize = 10;
        pt.MarkerStyle = MarkerStyle.Circle;
       // pt.ToolTip = "Value :" + pt.YValues[0].ToString() + "\n Phase : R Phase";
        i++;
    }

    Title tit = new Title("Line chart from " + startDate + " to " + EndDate, Docking.Top, new Font("Garamond", 14), Color.Black);
    Chart1.Titles.Add(tit);

1 个答案:

答案 0 :(得分:0)

之前我遇到过类似的问题。

Chart1.Series[0].IsXValueIndexed = false; 
Chart1.Series[0].XValueType = ChartValueType.Time;

可以解决问题。