Я борюсь с графическим дисплеем MS C# и прокруткой по оси Y. Что я хочу сделать, так это то, что когда я сдвигаю полосу прокрутки оси Y, основной слайд сетки тоже. Но основная сетка фиксирована, а ярлык меняется. Ось Y - это «стиль номера». Ось X - это стиль «datetime». Когда я прокручиваю ось X, прокручивается дата. Это хорошо синхронизировано. Но это не так для оси Y. Я пытаюсь изменить YAxis.LabelStyle и YAxis.MajorGrid без успеха.C# диаграмма Сетка оси Y и прокрутка меток
Ниже приведен исходный код этого вопроса.
// Create new Graph
chart = new Graph.Chart();
// Définition de la taille et du modèle de chart
chart.Location = new System.Drawing.Point(10, 10);
chart.Size = new System.Drawing.Size(700, 700);
chart.BackGradientStyle = Graph.GradientStyle.LeftRight;
chart.BorderSkin.SkinStyle = Graph.BorderSkinStyle.Emboss;
// Add a chartarea called "draw", add axes to it and color the area black
chart.ChartAreas.Add("draw");
// Définition axe X (secondes). Largeur 200s, interval = 10s, label toutes les 30s
chart.ChartAreas["draw"].AxisX.IntervalType = Graph.DateTimeIntervalType.Seconds;
chart.ChartAreas["draw"].AxisX.Interval = 10; // Ajoute une trait à chaque interval de 10s sur l'axe (attention, c'est différent de la grille !!!)
chart.ChartAreas["draw"].AxisX.Title = "Temps";
chart.ChartAreas["draw"].AxisX.IntervalOffsetType = Graph.DateTimeIntervalType.Seconds;
chart.ChartAreas["draw"].AxisX.LabelStyle.IntervalType = Graph.DateTimeIntervalType.Seconds;
chart.ChartAreas["draw"].AxisX.LabelStyle.IntervalOffsetType = Graph.DateTimeIntervalType.Seconds;
chart.ChartAreas["draw"].AxisX.LabelStyle.Interval = 30; // Ajoute un label toutes les 30s
chart.ChartAreas["draw"].AxisX.LabelStyle.IntervalOffset = 0D;
chart.ChartAreas["draw"].AxisX.LabelStyle.Format = "H:mm:ss";
chart.ChartAreas["draw"].AxisX.Minimum = 0; // En nombre de jour ! (pourquoi, je sais pas)
chart.ChartAreas["draw"].AxisX.Maximum = 200.0/(24.0*60*60.0); // En nombre de jour ! Donc 200s => 200s/(24h*60m*60s)
// Définition grille axe X . Interval tous les 10s, lignes tirets blancs
chart.ChartAreas["draw"].AxisX.MajorGrid.Interval = 10; // 10s entre chaque graduation (grille traversant l'axe X verticalement)
chart.ChartAreas["draw"].AxisX.MajorGrid.IntervalType = Graph.DateTimeIntervalType.Seconds;
chart.ChartAreas["draw"].AxisX.MajorGrid.IntervalOffset = 0D;
chart.ChartAreas["draw"].AxisX.MajorGrid.IntervalOffsetType = Graph.DateTimeIntervalType.Seconds;
chart.ChartAreas["draw"].AxisX.MajorGrid.LineColor = Color.White;
chart.ChartAreas["draw"].AxisX.MajorGrid.LineDashStyle = Graph.ChartDashStyle.Dash;
// Définition axe Y (nombre). Min = -0.4 Max = 1 Interval = 0.2
chart.ChartAreas["draw"].AxisY.Minimum = -0.4;
chart.ChartAreas["draw"].AxisY.Maximum = 1;
chart.ChartAreas["draw"].AxisY.Interval = 0.2;
chart.ChartAreas["draw"].AxisY.LabelStyle.IntervalType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].AxisY.LabelStyle.IntervalOffsetType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].AxisY.LabelStyle.Interval = 0.1; // Ajoute un label tous les 0.1
chart.ChartAreas["draw"].AxisY.LabelStyle.IntervalOffset = 0D;
chart.ChartAreas["draw"].AxisY.LabelStyle.Format = ".000";
// Définition grille axe Y . Interval tous les 0.1, lignes tirets blancs
chart.ChartAreas["draw"].AxisY.MajorGrid.Interval = 0.1; // 1 entre chaque graduation (grille traversant l'axe Y horizontalement)
chart.ChartAreas["draw"].AxisY.MajorGrid.IntervalType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].AxisY.MajorGrid.IntervalOffset = 0D;
chart.ChartAreas["draw"].AxisY.MajorGrid.IntervalOffsetType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].AxisY.MajorGrid.LineColor = Color.White;
chart.ChartAreas["draw"].AxisY.MajorGrid.LineDashStyle = Graph.ChartDashStyle.Dash;
// Définition grille axe secondaire Y . Lignes pointillées
chart.ChartAreas["draw"].AxisY2.MajorGrid.LineColor = Color.BurlyWood;
chart.ChartAreas["draw"].AxisY2.MajorGrid.LineDashStyle = Graph.ChartDashStyle.Dot;
// Couleur de fond du tracé
chart.ChartAreas["draw"].BackColor = Color.Black;
// Create two new functions series
chart.Series.Add("MyFunc");
chart.Series.Add("MyFunc2");
// Set the type to line
chart.Series["MyFunc"].ChartType = Graph.SeriesChartType.Line;
chart.Series["MyFunc2"].ChartType = Graph.SeriesChartType.Line;
// Ajouter un tooltip sur la valeur pointée
chart.Series["MyFunc"].ToolTip = "#VAL";
chart.Series["MyFunc2"].ToolTip = "#VAL";
// Color the line of the graph light green and give it a thickness of 3
chart.Series["MyFunc"].Color = Color.LightGreen;
chart.Series["MyFunc"].BorderWidth = 3;
chart.Series["MyFunc2"].Color = Color.Bisque;
chart.Series["MyFunc2"].BorderWidth = 3;
// Définition des types de données sur les axes X et Y des séries de données
chart.Series["MyFunc"].XValueType = Graph.ChartValueType.DateTime;
chart.Series["MyFunc"].YValueType = Graph.ChartValueType.Double;
chart.Series["MyFunc"].XAxisType = Graph.AxisType.Primary;
chart.Series["MyFunc"].YAxisType = Graph.AxisType.Primary;
chart.Series["MyFunc2"].XValueType = Graph.ChartValueType.DateTime;
chart.Series["MyFunc2"].YValueType = Graph.ChartValueType.Double;
chart.Series["MyFunc2"].XAxisType = Graph.AxisType.Primary;
chart.Series["MyFunc2"].YAxisType = Graph.AxisType.Secondary;
//This function cannot include zero, and we walk through it in steps of 0.1 to add coordinates to our series
DateTime dto;
dto = new DateTime();
for (double x = 0.1; x < 20; x += 0.1)
{
chart.Series["MyFunc"].Points.AddXY(dto, Math.Sin(x)/x);
chart.Series["MyFunc2"].Points.AddXY(dto, Math.Cos(x)/x);
dto = dto.AddSeconds(1);
}
// Ajout des légendes
chart.Series["MyFunc"].LegendText = "sin(x)/x";
chart.Series["MyFunc2"].LegendText = "cos(x)/x";
// Create a new legend called "MyLegend".
chart.Legends.Add("MyLegend");
chart.Legends["MyLegend"].BorderColor = Color.Tomato; // I like tomato juice!
// Autorisation de zoomer
chart.ChartAreas["draw"].AxisY.ScaleView.Zoomable = true;
chart.ChartAreas["draw"].AxisY2.ScaleView.Zoomable = true;
chart.ChartAreas["draw"].AxisX.ScaleView.Zoomable = true;
// Définition des curseurs en X et Y afin de pouvoir sélectionner la zone à zoomer
chart.ChartAreas["draw"].CursorX.IsUserSelectionEnabled = true;
chart.ChartAreas["draw"].CursorX.IntervalOffsetType = Graph.DateTimeIntervalType.Milliseconds;
chart.ChartAreas["draw"].CursorX.IntervalType = Graph.DateTimeIntervalType.Milliseconds;
chart.ChartAreas["draw"].CursorX.IsUserEnabled = true;
chart.ChartAreas["draw"].CursorY.IsUserEnabled = true;
chart.ChartAreas["draw"].CursorY.IntervalOffsetType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].CursorY.IntervalType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].CursorY.IsUserSelectionEnabled = true;
chart.ChartAreas["draw"].CursorY.Interval = 0.001; // Valeur minimum sélectionnable par l'utilisateur (on ne peut pas zoomer au delà)
// Définition des mises à l'échelles et des barres de défilements axe X et Y
chart.ChartAreas["draw"].AxisX.ScaleBreakStyle.Enabled = true;
chart.ChartAreas["draw"].AxisX.ScaleView.MinSize = 0D;
chart.ChartAreas["draw"].AxisX.ScaleView.MinSizeType = Graph.DateTimeIntervalType.Milliseconds;
chart.ChartAreas["draw"].AxisX.ScaleView.SizeType = Graph.DateTimeIntervalType.Milliseconds;
chart.ChartAreas["draw"].AxisX.ScaleView.SmallScrollMinSize = 0D;
chart.ChartAreas["draw"].AxisX.ScaleView.SmallScrollMinSizeType = Graph.DateTimeIntervalType.Milliseconds;
chart.ChartAreas["draw"].AxisX.ScaleView.SmallScrollSizeType = Graph.DateTimeIntervalType.Milliseconds;
chart.ChartAreas["draw"].AxisY.ScaleView.MinSize = 0.1D;
chart.ChartAreas["draw"].AxisY.ScaleView.MinSizeType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].AxisY.ScaleView.SizeType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].AxisY.ScaleView.SmallScrollMinSize = 0.001D;
chart.ChartAreas["draw"].AxisY.ScaleView.SmallScrollMinSizeType = Graph.DateTimeIntervalType.Number;
chart.ChartAreas["draw"].AxisY.ScaleView.SmallScrollSizeType = Graph.DateTimeIntervalType.Number;
//chart.ChartAreas["draw"].AxisY.LabelStyle.IsStaggered = false;
// Couleur des scrollbars
chart.ChartAreas["draw"].AxisX.ScrollBar.BackColor = Color.AliceBlue;
chart.ChartAreas["draw"].AxisX.ScrollBar.ButtonColor = Color.LightBlue;
chart.ChartAreas["draw"].AxisY.ScrollBar.BackColor = Color.AliceBlue;
chart.ChartAreas["draw"].AxisY.ScrollBar.ButtonColor = Color.LightBlue;
// On ajoute à la form le chart (sinon, on ne sait pas ou l'afficher !)
Controls.Add(this.chart);
}
У вас есть идея сделать это. Он хорошо работает для оси X без какого-либо кода, но не для оси Y. Я думаю, что можно что-то сделать с событием AxisChanged, но довольно сложно. Надеюсь, мой вопрос ясен! Английский язык не мой любимый язык!
NB: Я использую Visual Studio 2015 и Framework 4.0 –
Я заметил этот «chart.ChartAreas [" draw "]. AxisY.Interval = 0.2;' Где вы указываете интервал YAxis. Этикетка зависит от нее. – WagoL
Привет, WagoL, у меня есть подавленная диаграмма. Черты ["draw"]. AxisY.Interval = 0.2; в исходном коде. Результат такой же, как и с линией. Я пытаюсь решить проблему с событием AxisViewChanged (без успеха) –