折磨小弟我的mschart有关问题


折磨我的mschart问题
看下面的代码


private void ShowPoints()

  {


    //make the chart can scroll and zoom

    Chart1.ChartAreas[0].CursorX.IsUserEnabled = true;

    Chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;

    Chart1.ChartAreas[0].CursorX.Interval = 1;

    Chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Days;//notice here

    Chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;

    Chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;

    //Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm";



    // Populate series data

    double[] yValues = { 2.8684, 2.8994, 2.9252, 2.9557, 2.9714, 2.9136, 3.0097, 2.8994, 2.9854, 2.8993, 2.9646, 2.9140 };

    DateTime currentDate = DateTime.Now;

    Random  random = new Random();

    Chart1.Series["Series1"].Points.Clear();

    for(int pointIndex = 0; pointIndex < 12; pointIndex++)

    {

     Chart1.Series["Series1"].Points.AddXY(currentDate, yValues[pointIndex]);

     currentDate = currentDate.AddDays(random.Next(1, 5));//notice here


    }

            

}


上面的代码工作正常,可以进行缩放并能拖动滚动条和scroll滚动条(就是滚动条可以拖动并且点击滚动条空白的地方也能移动滚动条。)但如果改成下面的代码,就不能拖动滚动条了,但点击空白的地方还是可以移动的。不知道是为什么,大家有什么办法可以解决吗。


private void ShowPoints()

  {


    //make the chart can scroll and zoom

    Chart1.ChartAreas[0].CursorX.IsUserEnabled = true;

    Chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;

    Chart1.ChartAreas[0].CursorX.Interval = 1;

    Chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.minutes;//变了,而且改成hours也一样

    Chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;

    Chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;

    //Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm";



    // Populate series data

    double[] yValues = { 2.8684, 2.8994, 2.9252, 2.9557, 2.9714, 2.9136, 3.0097, 2.8994, 2.9854, 2.8993, 2.9646, 2.9140 };

    DateTime currentDate = DateTime.Now;

    Random  random = new Random();

    Chart1.Series["Series1"].Points.Clear();

    for(int pointIndex = 0; pointIndex < 12; pointIndex++)

    {

     Chart1.Series["Series1"].Points.AddXY(currentDate, yValues[pointIndex]);

     currentDate = currentDate.Addminutes(random.Next(1, 5));//变了,而且改成hours也一样


    }

            

}


 


相关链接

.net 程序开发 用户自定义控件

muriko 12 years, 2 months ago

Your Answer