I am using chart in real time, feeding it by seperated thread. But everytime I add another series and legend that legend pushes chart away making it smaller. I can not find any solution to this.
This is my function for setting up chart before any series are added:
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();
When I add series/points:
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();
}
Without this line:
chart1.Series[name].Legend = name;
It seems to connect all legend into one "DIV" but still, it always stacks legend in a way that shrinks the chart:
Picture is WITH this line.
How to do I setup legend so it would not change the size of the chart?