当前位置: 首页 > 工具软件 > ZedGraph > 使用案例 >

C#利用zedgraph绘制曲线

赏星河
2023-12-01

c#利用zedgraph绘制三通道曲线,并且可以根据通道选项情况有选择地展示数据,同时在曲线绘制好以后利用zedgraph的恢复默认大小功能使得曲线最大程度地展现在图形显示区域内。

private void DataPro() // 数据处理
{
    try
    {
        int max_x = data_ch1.Count;
        if (max_x % 10 != 0)
        {
            max_x += (10 - (max_x % 10));
        }

        RollingPointPairList list1 = new RollingPointPairList(max_x);
        RollingPointPairList list2 = new RollingPointPairList(max_x);
        RollingPointPairList list3 = new RollingPointPairList(max_x);

        zedGraphControl1.GraphPane.CurveList[0] = zedGraphControl1.GraphPane.AddCurve("通道1", list1, Color.Blue, SymbolType.None);
        zedGraphControl1.GraphPane.CurveList[1] = zedGraphControl1.GraphPane.AddCurve("通道2", list2, Color.Red, SymbolType.None);
        zedGraphControl1.GraphPane.CurveList[2] = zedGraphControl1.GraphPane.AddCurve("通道3", list3, Color.Green, SymbolType.None);

        zedGraphControl1.GraphPane.XAxis.Scale.Min = 0; //X轴最小值0
        zedGraphControl1.GraphPane.XAxis.Scale.Max = max_x; //X轴最大30
        zedGraphControl1.GraphPane.XAxis.Scale.MinorStep = 1;//X轴小步长1,也就是小间隔
        zedGraphControl1.GraphPane.XAxis.Scale.MajorStep = 5;//X轴大步长为5,也就是显示文字的大间隔

        zedGraphControl1.GraphPane.YAxis.Scale.MaxAuto = true; // 根据数值的大小自动设置Y轴最大值
        zedGraphControl1.GraphPane.YAxis.Scale.MinAuto = true; // 根据数值的大小自动设置Y轴最小值

        zedGraphControl1.Refresh();
        zedGraphControl1.RestoreScale(zedGraphControl1.GraphPane);          //恢复默认大小
		for (int i = 0; i < data_ch1.Count; i++) 
        {
            zedGraphControl1.GraphPane.CurveList[0].AddPoint(i + 1, data_ch1[i]);
            zedGraphControl1.GraphPane.CurveList[1].AddPoint(i + 1, data_ch2[i]);
            zedGraphControl1.GraphPane.CurveList[2].AddPoint(i + 1, data_ch3[i]);
            // data_ch1, data_ch2, data_ch3分别为存放通道1,通道2和通道3数据的数组
        }
        if (!checkBox1.Checked) // 通道1选项框未勾选情况
        {
            zedGraphControl1.GraphPane.CurveList[0].IsVisible = false;
            zedGraphControl1.Refresh();
            zedGraphControl1.RestoreScale(zedGraphControl1.GraphPane);          //恢复默认大小
        }
        
        if (!checkBox2.Checked) // 通道2选项框未勾选情况
        {
            zedGraphControl1.GraphPane.CurveList[1].IsVisible = false;
            zedGraphControl1.Refresh();
            zedGraphControl1.RestoreScale(zedGraphControl1.GraphPane);          //恢复默认大小
        }

        if (!checkBox3.Checked) // 通道3选项框未勾选情况
        {
            zedGraphControl1.GraphPane.CurveList[2].IsVisible = false;
            zedGraphControl1.Refresh();
            zedGraphControl1.RestoreScale(zedGraphControl1.GraphPane);          //恢复默认大小
        }
    }
    catch
    {
        
    }
}
 类似资料: