Я использую график в режиме реального времени, питая его отдельным потоком. Но каждый раз, когда я добавляю другую серию и легенду, эта легенда отталкивает график, делая его меньше. Я не могу найти решение этой проблемы.
Это моя функция для настройки графика перед добавлением любой серии:
chart1.BackColor = Color.DarkGray;
chart1.ForeColor = Color.White;
chart1.ChartAreas[0].BackColor = Color.WhiteSmoke;
chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
chart1.ChartAreas[0].AxisX.LineColor = Color.White;
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.DarkGray;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
chart1.ChartAreas[0].AxisY.LineColor = Color.White;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.DarkGray;
chart1.ChartAreas[0].AxisX.Interval = 5;
chart1.ChartAreas[0].AxisX.IntervalOffset = 1;
chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;
//SetX();
DateTime act = DateTime.Now;
DateTime max = act.AddSeconds(60);
//DateTime min = act.AddSeconds(-30);
chart1.ChartAreas[0].AxisX.Minimum = act.ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = max.ToOADate();
Когда я добавляю серии / очки:
if (chart1.Legends.IndexOf(name) == -1)
{
//Legend
chart1.Legends.Add(name);
chart1.Legends[name].Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Left;
chart1.Legends[name].LegendStyle = System.Windows.Forms.DataVisualization.Charting.LegendStyle.Column;
}
// Must exists
if (chart1.Series.IndexOf(name) == -1)
{
// Series
chart1.Series.Add(name);
chart1.Series[name].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StepLine;
chart1.Series[name].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
chart1.Series[name].BorderWidth = 4;
chart1.Series[name].Legend = name;
}
DateTime act = DateTime.Now;
//Get value from string
switch (format)
{
case "BOOL":
int boolval = value.ToUpper() == "TRUE" ? 1 : 0;
chart1.Series[name].Points.AddXY(act, boolval);
break;
case "DEC":
int intval = Int32.Parse(value);
chart1.Series[name].Points.AddXY(act, intval);
break;
case "FLOAT":
float fvalue = float.Parse(value);
chart1.Series[name].Points.AddXY(act, fvalue);
break;
}
if (act.ToOADate() >= chart1.ChartAreas[0].AxisX.Maximum)
{
SetX();
}
Без этой строки:
chart1.Series[name].Legend = name;
Кажется, что все легенды объединены в один "DIV", но тем не менее, он всегда складывает легенду таким образом, что сокращает график:
Изображение с этой строкой.
Как настроить легенду, чтобы она не меняла размер диаграммы?