Приветствую вас. В общем проблема при скралинге графика скролл рывками как можно решить проблему подскажите. Вот код Код | using System; using System.Data; using System.Drawing; using System.Windows.Forms; using ZedGraph; using System.Data.SQLite;
namespace DrawTestForm { public partial class Form1 : Form { MasterPane _masterPane = new MasterPane(); private string _path = $"{Application.StartupPath}\\Test.db"; SQLiteConnection _connection; SQLiteConnectionStringBuilder _connstr = new SQLiteConnectionStringBuilder(); private int _begin = 0; private int _end = 4000; private int _scrollCount = 400; private int newMinValue = 0; private int newMaxValue = 0;
DataTable _data = new DataTable();
public Form1() { _connstr.DataSource = _path; _connection = new SQLiteConnection(_connstr.ConnectionString); _connection.Open(); _data = GetTable(_begin, _end);
InitializeComponent(); zedGraphControl1.MouseWheel += ZedGraphControl1OnMouseWheel; zedGraphControl1.Dock = DockStyle.Fill; FillMP(); }
private void ZedGraphControl1OnMouseWheel(object sender, MouseEventArgs mouseEventArgs) { if (mouseEventArgs.Delta > 0 && zedGraphControl1.GraphPane.YAxis.Scale.Min > zedGraphControl1.ScrollMinY) { ScrollPane(ScrollState.Up); Scroll(ScrollState.Up, (int)zedGraphControl1.GraphPane.YAxis.Scale.Min, newMinValue); } if (mouseEventArgs.Delta < 0 && zedGraphControl1.GraphPane.YAxis.Scale.Max < zedGraphControl1.ScrollMaxY) { ScrollPane(ScrollState.Down); Scroll(ScrollState.Down, newMaxValue, (int)zedGraphControl1.GraphPane.YAxis.Scale.Max); } newMaxValue = (int)zedGraphControl1.GraphPane.YAxis.Scale.Max; newMinValue = (int)zedGraphControl1.GraphPane.YAxis.Scale.Min; this.Refresh(); }
void ScrollPane(ScrollState scrollState) { foreach (GraphPane pane in _masterPane.PaneList) { if (scrollState == ScrollState.Up) { pane.YAxis.Scale.Min -= _scrollCount; pane.YAxis.Scale.Max -= _scrollCount; } else { pane.YAxis.Scale.Min += _scrollCount; pane.YAxis.Scale.Max += _scrollCount; } } }
private void FillMP() { _masterPane.PaneList.Clear(); _masterPane.InnerPaneGap = 0; _masterPane.TitleGap = 0; _masterPane.BaseDimension = 100; int count = 0; for (int i = 1; i < 6; i++) { GraphPane pane = new GraphPane(); gp(pane); count = CreateCurve(pane, count); _masterPane.PaneList.Add(pane); }
using (Graphics g = zedGraphControl1.CreateGraphics()) {
_masterPane.SetLayout(g, PaneLayout.SingleRow); }
this.zedGraphControl1.MasterPane = _masterPane;
}
int CreateCurve(GraphPane pane, int newCount) { int count = newCount; for (int i = 0; i < 6; i++) { count++; LineItem line = pane.AddCurve("", CreatePointList(count), GetRanColor(), SymbolType.None); } return count; }
DataTable GetTable(int beginId, int endId) { DataTable dataTable = new DataTable(); SQLiteCommand command = new SQLiteCommand($"Select * From TestTable Where Id < {endId} AND Id > {beginId} ", _connection); using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(command)) { adapter.Fill(dataTable); } return dataTable; }
DataSourcePointList CreatePointList(int index) { DataSourcePointList source = new DataSourcePointList(); source.DataSource = _data; source.YDataMember = "Id"; source.XDataMember = $"X{index}"; return source; }
void gp(GraphPane pane) { pane.YAxis.IsVisible = true; pane.YAxis.Title.Text = ""; pane.YAxis.Scale.IsLabelsInside = true; pane.YAxis.Scale.IsSkipFirstLabel = true; pane.YAxis.Scale.IsSkipLastLabel = true; pane.YAxis.Scale.IsReverse = true; pane.YAxis.Scale.IsVisible = true;
pane.YAxis.Scale.Min = _begin; pane.YAxis.Scale.Max = _end;
pane.YAxis.Scale.MajorStepAuto = false; pane.YAxis.Scale.MinorStepAuto = false; pane.YAxis.Scale.MinAuto = false; pane.YAxis.Scale.MaxAuto = false; pane.YAxis.Scale.MagAuto = false; pane.YAxis.Scale.MajorStep = 500; pane.YAxis.Scale.MinorStep = 250; pane.YAxis.MajorGrid.IsVisible = false; pane.YAxis.MinorGrid.IsVisible = false;
pane.XAxis.Scale.Min = 0; pane.XAxis.Scale.Max = 320; pane.XAxis.Scale.MajorStep = 50; pane.XAxis.Scale.MinorStep = 25; }
Random rdn = new Random();
Color GetRanColor() {
int r = rdn.Next(byte.MaxValue); int g = rdn.Next(byte.MaxValue); int b = rdn.Next(byte.MaxValue); return Color.FromArgb(r, g, b); }
public void Scroll(ScrollState scrollState, int beginId, int endId) { DataTable tmpTable = GetTable(beginId, endId); if (scrollState == ScrollState.Up) { for (int i = tmpTable.Rows.Count - 1; i > 0; i--) { DataRow tmpRow = _data.NewRow(); tmpRow.ItemArray = tmpTable.Rows[i].ItemArray; _data.Rows.RemoveAt(_data.Rows.Count - 1); _data.Rows.InsertAt(tmpRow, 0);
}
} else { for (int i = 0; i < tmpTable.Rows.Count - 1; i++) { _data.Rows.Add(tmpTable.Rows[i].ItemArray); _data.Rows.RemoveAt(0); } } }
private void zedGraphControl1_ScrollEvent(object sender, ScrollEventArgs e) { if (e.NewValue > e.OldValue) { Scroll(ScrollState.Down, newMaxValue, (int)zedGraphControl1.GraphPane.YAxis.Scale.Max); } if (e.NewValue < e.OldValue) { Scroll(ScrollState.Up, (int)zedGraphControl1.GraphPane.YAxis.Scale.Min, newMinValue); } newMaxValue = (int)zedGraphControl1.GraphPane.YAxis.Scale.Max; newMinValue = (int)zedGraphControl1.GraphPane.YAxis.Scale.Min; } }
public enum ScrollState { Up, Down } }
|
|