I have a list of signals in a listview. When the user checks one, the values of the signals are being plotted on the chart. Moreover there is a vertical annotation which the user can drag across the graph and see the values for every x value. Each signal has one rectangle annotation that shows the Y value.
My problem is that when the user checks a new signal then the old rectangle annotations do not disappear.
Here is what I mean :
enter image description here
Here is my code so far :
List<RectangleAnnotation> anno = new List<RectangleAnnotation>();
List<Series> checkedItems = new List<Series>();
private void listView1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (listView1.FocusedItem != null)
{
double xFactor = 0.03;
double yFactor = 0.02;
CA = chart1.ChartAreas[0];
if (e.NewValue == CheckState.Checked)
{
anno.Clear();
Series s12 = new Series();
s12 = chart1.Series.Add((listView1.Items[e.Index].Text).ToString());
s12.ChartType = SeriesChartType.Line;
s12.MarkerStyle = MarkerStyle.Circle; // make the points stand out
s12.MarkerSize = 3;
checkedItems.Add(s12);
for (int i = 0; i < chart1.Series.Count - 1; i++)
{
anno.Add(new RectangleAnnotation());
anno[i].AxisX = CA.AxisX;
anno[i].IsSizeAlwaysRelative = false;
anno[i].Width = 20 * xFactor;
anno[i].Height = 8 * yFactor;
// VA.Name = "myRect";
anno[i].LineColor = Color.Black;
anno[i].BackColor = Color.Black;
anno[i].AxisY = CA.AxisY;
anno[i].Y = -anno[i].Height;
// RA[i].X = VA.X - RA[i].Width / 2;
anno[i].Text = "Hello";
anno[i].ForeColor = Color.Black;
anno[i].Font = new System.Drawing.Font("Arial", 8f);
anno[i].Text = String.Format("{0:0.00}", 0);
chart1.Annotations.Add(anno[i]);
}
for (int r = 0; r < num_rows; r++)
{
DataPoint dp = new DataPoint();
dp.SetValueXY(r, values[r, listView1.Items.IndexOf(listView1.Items[e.Index])]);
// chart1.Series[checkedListBox1.Items[e.Index].ToString()].Points.Add(dp);
s12.Points.AddXY(r, values[r, listView1.Items.IndexOf(listView1.Items[e.Index])]);
}
}
}
}
private void chart1_AnnotationPositionChanging(object sender, AnnotationPositionChangingEventArgs e)
{
int pt1 = (int)e.NewLocationX;
int i = 0;
foreach (var signal in checkedItems) {
double val = signal.Points[pt1].YValues[0];
foreach (var sim in signal.Points[pt1].YValues)
{
anno[i].Y = sim + 0.5;
}
if (sender == VA) anno[i].X = VA.X - anno[i].Width / 2;
anno[i].Text = String.Format("{0:0.00}", val);
i++;
Console.WriteLine(anno.Count);
}
I have thought of adding
chart1.Annotations.clear();
But it deletes all Annotations including the vertical. I only want to delete the rectangle annotations.
Related
I had Gantt chart like this. I'd like to show AxisX2 with value is percentage that I prepared formula for it. I had challenges to show AxisX2 and set series for it.
Here is the Gantt chart I captured click here.
I expect to one more axis like this.
Please help, Thank you .
Here are some basic function to render that chart
public void setUpGantt(Chart chart)
{
chart.Series.Clear();
Series s = chart.Series.Add("sszs");
s.ChartType = SeriesChartType.RangeBar;
s.YValueType = ChartValueType.DateTime;
s.ResetIsVisibleInLegend () ;
s.IsVisibleInLegend = true;
Axis ax = chart.ChartAreas[0].AxisX;
Axis ay = chart.ChartAreas[0].AxisY;
ax.MajorGrid.Enabled = false;
ay.IntervalType = DateTimeIntervalType.Minutes;
ay.Interval = 60;
ay.LabelStyle.Format = "HH:mm";
ay.Minimum = 0;
ay.Maximum = 0.2;
limitGantt(chart, "0:00", "24:00");
s.ToolTip = "#VALY1{HH:mm}~#VALY2{HH:mm}";
}
public void limitGantt(Chart chart, string start, string end)
{
Axis ax = chart.ChartAreas[0].AxisX;
Axis ay = chart.ChartAreas[0].AxisY;
ay.Minimum = fromTimeString(start).ToOADate();
ay.Maximum = fromTimeString(end).ToOADate();
}
DateTime fromTimeString(string time)
{
var p = time.Split(':');
int sec = p.Length == 3 ? Convert.ToInt16(p[2]) : 0;
TimeSpan t = new TimeSpan(Convert.ToInt16(p[0]), Convert.ToInt16(p[1]), sec);
return DateTime.Today.Add(t);
}
public void addGanttTask(Series s, string start, string end, Color c, int slot, string [] array)
{
DateTime start_ = fromTimeString(start);
DateTime end_ = fromTimeString(end);
int pt = s.Points.AddXY(slot, start_, end_);
s.Points[pt].Color = c;
s.IsVisibleInLegend = true;
if (array != null)
{
for (int i = 0; i < array.Length; i++)
{
if (slot == i + 1)
{ s.Points[pt].AxisLabel = array[i];
}
}
}
}
Taw's comment
public void setUpGantt(Chart chart)
{
chart.Series.Clear();
Series s = chart.Series.Add("sszs");
s.ChartType = SeriesChartType.RangeBar;
s.YValueType = ChartValueType.DateTime;
s.ResetIsVisibleInLegend () ;
s.IsVisibleInLegend = true;
Axis ax = chart.ChartAreas[0].AxisX;
Axis ay = chart.ChartAreas[0].AxisY;
ax.MajorGrid.Enabled = false;
Axis ax2 = chart.ChartAreas[0].AxisX2;
ax2.Enabled = AxisEnabled.True;
ax2.Maximum = 100;
ax2.MajorGrid.Enabled = false;
ay.IntervalType = DateTimeIntervalType.Minutes;
ay.Interval = 60;
ay.LabelStyle.Format = "HH:mm";
ay.Minimum = 0;
ay.Maximum = 0.2;
limitGantt(chart, "0:00", "24:00");
s.ToolTip = "#VALY1{HH:mm}~#VALY2{HH:mm}";
}
I'd like to have percentage = Green Time/Total time (from 00:
00 to Current time) example
Thank you for TaW's suggestion. It worked for me.
I post here to share who want to know
public void setUpGantt(Chart chart)
{
chart.Series.Clear();
Series s = chart.Series.Add("sszs");
s.ChartType = SeriesChartType.RangeBar;
s.YValueType = ChartValueType.DateTime;
s.ResetIsVisibleInLegend () ;
s.IsVisibleInLegend = true;
Axis ax = chart.ChartAreas[0].AxisX;
Axis ay = chart.ChartAreas[0].AxisY;
ax.MajorGrid.Enabled = false;
Axis ax2 = chart.ChartAreas[0].AxisX2;
ax2.Enabled = AxisEnabled.True;
ax2.MajorGrid.Enabled = true;
ax2.CustomLabels.Clear();// clear previous value when switch another data
for (int i = 0; i < 12; i++)
{
CustomLabel cl = new CustomLabel();
cl.FromPosition = i+0.5;
cl.ToPosition = i+1.5;
cl.Text = i+" %"; // example value to show on CustomLabel
ax2.CustomLabels.Add(cl);
}
ay.IntervalType = DateTimeIntervalType.Minutes;
ay.Interval = 60;
ay.LabelStyle.Format = "HH:mm";
ay.Minimum = 0;
ay.Maximum = 0.2;
limitGantt(chart, "0:00", "24:00");
s.ToolTip = "#VALY1{HH:mm}~#VALY2{HH:mm}";
}
The main script to show one more Axis with CustomLabel
Axis ax2 = chart.ChartAreas[0].AxisX2;
ax2.Enabled = AxisEnabled.True;
ax2.MajorGrid.Enabled = true;
ax2.CustomLabels.Clear();// clear previous value when switch another data
for (int i = 0; i < 12; i++)
{
CustomLabel cl = new CustomLabel();
cl.FromPosition = i+0.5;
cl.ToPosition = i+1.5;
cl.Text = i+" %"; // example value to show on CustomLabel
ax2.CustomLabels.Add(cl);
}
I have C# project already done but im having issue with printing it's charts when comes out with more pages of data points, i got the scroll bar work when start getting more pages so the user can review all data on all pages but i could not find how to make the print preview shows them or print them,
when click on print, it shows only the first page on the print preview and same thing when print it out.
her is the print code:
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = this.chart1.Printing.PrintDocument;
((Form)ppd).WindowState = FormWindowState.Maximized;
chart1.Printing.PrintDocument.DefaultPageSettings.Landscape = true;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Left = 0;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Right = 0;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Top = 0;
chart1.Printing.PrintDocument.DefaultPageSettings.Margins.Bottom = 0;
ppd.ShowDialog();
and here is the chart load code:
public void loadChart(string sqlvalue)//load chart method
{
chart1.ChartAreas[0].AxisY.Maximum = 55;
chart1.ChartAreas[0].AxisY.Minimum = 35;
chart1.ChartAreas[0].AxisY.Interval = 5;//control how many lines/Interval
chart1.ChartAreas[0].AxisY.ScrollBar.Enabled = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.Minimum = 0;
// chart1.ChartAreas[0].AxisX.Maximum = 10;
chart1.ChartAreas[0].AxisX.Interval = 1;
//X AXES label angle
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 60;
da = new SqlDataAdapter(sqlvalue, cn.connect());
da.Fill(dt);
this.chart1.DataSource = dt;
this.chart1.Series["left"].XValueMember = dt.Columns[3].ToString();//date data
this.chart1.Series["left"].YValueMembers = dt.Columns[1].ToString();//spindle 1 data
this.chart1.Series["Right"].YValueMembers = dt.Columns[2].ToString();//spindle 2 data
//label the series lines, Backcolor and forcolor
chart1.Series[0].LabelBackColor = Color.Red;
chart1.Series[0].LabelForeColor = Color.White;
//datapoint marker's color, bordercolor,style and size
chart1.Series[0].MarkerColor = Color.White;
chart1.Series[0].MarkerBorderColor = Color.Black;
chart1.Series[0].MarkerStyle = MarkerStyle.Circle;
chart1.Series[0].MarkerSize = 8;
//datapoint marker's color, style and size
chart1.Series[1].MarkerColor = Color.White;
chart1.Series[1].MarkerBorderColor = Color.Black;
chart1.Series[1].MarkerStyle = MarkerStyle.Circle;
chart1.Series[1].MarkerSize = 8;
chart1.Series[1].LabelBackColor = Color.Blue;
chart1.Series[1].LabelForeColor = Color.White;
//Chart background lines color
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Silver;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Silver;
this.chart1.DataBind();
cn.disconnect();
// enable autoscroll
chart1.ChartAreas[0].CursorX.AutoScroll = true;//------------
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, 15);
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// set scrollbar small change to the target size
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = 15;
Legend left = new Legend();
Legend LC = CustomCloneLegend(chart1, left);
chart1.Legends.Add(LC);
chart1.Padding = Padding.Empty;
ChartArea CA = chart1.ChartAreas[0];
CA.Position = new ElementPosition(4,6, 100, 90);
}
Thank you for your time and help, here is the chart code update:
private static Image MergeImages(List<Image> imageList)
{
var finalSize = new Size();
foreach (var image in imageList)
{
if (image.Width > finalSize.Width)
{
finalSize.Width = image.Width;
}
finalSize.Height += image.Height;
}
var outputImage = new Bitmap(finalSize.Width, finalSize.Height);
using (var gfx = Graphics.FromImage(outputImage))
{
var y = 0;
foreach (var image in imageList)
{
gfx.DrawImage(image, 0, y);
y += image.Height;
}
}
return outputImage;
}
The second method:
List<Image> ChartsToImages(List<Chart> charts)
{
var imageList = new List<Image>();
foreach (var c in charts)
{
using (var ms = new MemoryStream())
{
c.SaveImage(ms, ChartImageFormat.Png);
var bmp = System.Drawing.Bitmap.FromStream(ms);
imageList.Add(bmp);
}
}
return imageList;
}
and this code
var chartList = new List<Chart> { chart1 };
var imageList = ChartsToImages(chartList);
var finalImage = MergeImages(imageList);
finalImage.Save("D:\\Junk.png", ImageFormat.Png);
Im not sure is that what you mean by your first comment, but i found this code here under Converting chart to image questions. this code convert and saves the chart in the same amount of pages but i need to show them in the printpreviewcontrol and print them.
Below code refers to the as per page count starting point and ending point based printing. And Grid view value chars are row loop based counting the page.
private int numberOfItemsPerPage = 0;
private int numberOfItemsPrintedSoFar = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int height = 480; //page height stating point
for (int l = numberOfItemsPrintedSoFar; l < dataGridView2.Rows.Count; l++)
{
numberOfItemsPerPage = numberOfItemsPerPage + 1;
if (numberOfItemsPerPage <= 25) // 25 is Page Line Item
{
numberOfItemsPrintedSoFar++;
if (numberOfItemsPrintedSoFar <= dataGridView2.Rows.Count)
{
height += dataGridView2.Rows[0].Height;
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[0].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(5, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[1].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(170, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[2].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(290, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
e.Graphics.DrawString(dataGridView2.Rows[l].Cells[3].FormattedValue.ToString(), dataGridView2.Font = new Font("Book Antiqua", 8), Brushes.Black, new RectangleF(345, height, dataGridView2.Columns[0].Width, dataGridView2.Rows[0].Height));
}
else
{
e.HasMorePages = false;
}
}
else
{
numberOfItemsPerPage = 0;
e.HasMorePages = true;
return;
}
}
numberOfItemsPerPage = 0;
numberOfItemsPrintedSoFar = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < pala.cantLetras; i++)
{ guiones[i] = new Label();
guiones[i].Text = "_";
guiones[i].Font = new Font("Berlin Sans FB Demi", 25);
guiones[i].Size = new Size(18, 37);
guiones[i].Name = "guion" + i;
guiones[i].ForeColor = Color.Black;
guiones[i].BackColor = Color.Transparent;
guiones[i].Location = new Point(x, 341);
this.Controls.Add(guiones[i]);
recguion[i] = guiones[i].Bounds;
recguion[i] = new Rectangle();
//recguion[i].Location = new Point(x, 341);
x = x + 50;
}
for (int i = 0; i < pala.cantLetras; i++)
{
labels[i] = new Label();
labels[i].Size = new Size(25, 55);
labels[i].Name = "label" + i;
labels[i].Text = pala.palabra[i].ToString();
labels[i].Font = new Font("Berlin Sans FB Demi", 20);
labels[i].ForeColor = Color.Black;
labels[i].BackColor = Color.Transparent;
labels[i].Location = new Point(y, 165);
this.Controls.Add(labels[i]);
posRandom[i] = y;
reclabel[i] = labels[i].Bounds;
reclabel[i] = new Rectangle();
// reclabel[i].Location = new Point(y, 165);
y = y + 40;
}
}
I need to know when reclabel[] intersects the recguion[] corresponding to that number.
Ex: reclabel[1] Intersects recguion[1] but only that one, if it intersects another it has to say that it's wrong.
The rectangles have inside(or that's what I a'm trying) labels[] and guiones[]
This is what I have tryied but it doesnt work.
private void intersecta()
{
int cont = 0;
for (int i = 0; i < pala.cantLetras; i++)
{
for (int j = 0; j < pala.cantLetras; j++)
{
if (i==j)
{
Rectangle intersect = Rectangle.Intersect(reclabel[i], recguion[j]);
if (intersect != Rectangle.Empty)
{
MessageBox.Show("Intersection!");
cont++;
}
}
if (cont != 0)
{
i = pala.cantLetras - 1;
j = pala.cantLetras - 1;
}
}
}
}
Thank you!
There is no need for a nested loop. Just loop through one array and check both rectangles at that index with .IntersectsWith. My apologies if there are any syntax errors, I don't have access to Visual Studio at the moment.
For(int i = 0; i < Array1.Length; i++)
{
if(Array1[i].IntersectsWith(Array2[i]))
{
//Intersected
}
}
But also, as Andrew pointed out, you have a serious problem here:
reclabel[i] = new Rectangle();
You are just overwriting all your data with a new instance (of a different type!).
I want to create a bar graph, like it scans something. In addition I want to change the color of the bar according to the x-axis interval at that time.
So far, I can managed the scanning function but when I try to change the colour of the bar, the whole bar is changing.
Here is my code :
namespace UDP
{
public partial class ScanGraph : Form
{
int boardCounter = 0;
int trackValue;
public ScanGraph()
{
InitializeComponent();
}
private void ScanGraph_Load(object sender, EventArgs e)
{
System.Windows.Forms.DataVisualization.Charting.Chart chart1 = new Chart();
ChartArea chartArea1 = new ChartArea("foobar");
chartArea1.Name = "ChartArea1";
Chart1.Series.Add("Head1");
Chart1.Series[1].ChartType = SeriesChartType.Bar;
Chart1.Series.Add("Head2");
Chart1.Series[2].ChartType = SeriesChartType.Bar;
Chart1.Series.Add("Head3");
Chart1.Series[3].ChartType = SeriesChartType.Bar;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 1;
Chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = true;
Chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
Chart1.ChartAreas[0].AxisY.Maximum = 100;
Chart1.ChartAreas[0].AxisY.Minimum = 0;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
Chart1.Series.Clear();
Chart1.Series.Add("Head1");
Chart1.Series[0].ChartType = SeriesChartType.Bar;
Chart1.Series.Add("Head2");
Chart1.Series[1].ChartType = SeriesChartType.Bar;
Chart1.Series.Add("Head3");
Chart1.Series[2].ChartType = SeriesChartType.Bar;
/*string black = "#000000";
string red = "#FF0000";
string blue = "#4981CE";
Color _color = System.Drawing.ColorTranslator.FromHtml(red);
if (boardCounter > 0 && boardCounter < 30)
{
_color = System.Drawing.ColorTranslator.FromHtml(black);
}
else if (boardCounter > 30 && boardCounter < 65)
{
_color = System.Drawing.ColorTranslator.FromHtml(red);
}
else if (boardCounter > 65 && boardCounter < 100)
{
_color = System.Drawing.ColorTranslator.FromHtml(blue);
}*/
Chart1.Series["Head1"].Points.AddY(boardCounter);
//Chart1.Series["Series2"].Color = _color;
Chart1.Series["Head2"].Points.AddY(boardCounter);
//Chart1.Series["Series3"].Color = _color;
Chart1.Series["Head3"].Points.AddY(boardCounter);
//Chart1.Series["Series4"].Color = _color;
boardCounter += 1;
if (boardCounter > 100) boardCounter = 1;
}
}
}
If you are changing the Color of the Series all bars/columns will change to that new Color. Instead you probably want to change only the Color of the Point(s) you want to change!
This will add a few Points to a Series and give each one a slightly different Color:
Series S1 = chart1.Series[0];
S1.ChartType = SeriesChartType.Column;
S1["PixelPointWidth"] = "3";
ChartArea CA = chart1.ChartAreas[0];
CA.AxisX.Minimum = 0;
CA.AxisX.Maximum = 100;
for (int d = 0; d <= 100; d ++)
{
S1.Points.AddXY(d, 100 + d * 3);
S1.Points[d].Color = Color.FromArgb(255, d, d * 2, 255 - d * 2);
}
i have Chart control that received real time data.
// MBit/Sec
Series seriesBps = new Series("bps");
seriesBps.Color = Color.Gray;
seriesBps.ChartType = SeriesChartType.Spline;
seriesBps.BorderWidth = 2;
seriesBps.Name = "MBit/Sec";
chart1.Series.Add(seriesBps);
//// Packets/Sec
Series seriesPps = new Series("pps");
seriesPps.Color = Color.SteelBlue;
seriesPps.ChartType = SeriesChartType.Spline;
seriesPps.BorderWidth = 2;
seriesPps.Name = "Packets/Sec";
chart1.Series.Add(seriesPps);
This is my timer tick event that need to add this data:
private void chartTimer_Tick(object sender, EventArgs e)
{
if (seriesBps.Points.Count() > 300)
seriesBps.Points.RemoveAt(0);
seriesBps.Points.Add(wf.BitsPerSecond * 0.000001);
DataPoint _point1 = default(DataPoint);
foreach (DataPoint item in chart1.Series[1].Points)
{
item.Label = "";
item.MarkerStyle = MarkerStyle.None;
}
chart1.Series[1].LegendText = chart1.Series[1].Name = (wf.BitsPerSecond * 0.000001).ToString("#,##0");
DataPoint Point1 = chart1.Series[1].Points[chart1.Series[1].Points.Count - 1];
Point1.Label = chart1.Series[1].Name;
chart1.Series[1].SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes;
chart1.Series[1].SmartLabelStyle.IsMarkerOverlappingAllowed = false;
chart1.Series[1].SmartLabelStyle.MovingDirection = LabelAlignmentStyles.BottomRight;
// --------------------------------------------------------------------------------------------------- //
if (seriesPps.Points.Count() > 300)
seriesPps.Points.RemoveAt(0);
seriesPps.Points.Add(wf.PacketsPerSecond);
DataPoint _point = default(DataPoint);
foreach (DataPoint item in chart1.Series[2].Points)
{
item.Label = "";
item.MarkerStyle = MarkerStyle.None;
}
chart1.Series[2].LegendText = chart1.Series[2].Name = wf.PacketsPerSecond.ToString("#,##0");
DataPoint Point = chart1.Series[2].Points[chart1.Series[2].Points.Count - 1];
Point.Label = chart1.Series[2].Name;
chart1.Series[2].SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes;
chart1.Series[2].SmartLabelStyle.IsMarkerOverlappingAllowed = false;
chart1.Series[2].SmartLabelStyle.MovingDirection = LabelAlignmentStyles.BottomRight;
chart1.ResetAutoValues();
}
This Chart work fine with the first Series but after add the second one received this error, i try to change the series name to something unique but i wont help
indexing starts at zero not 1, like any other for i loop . Move back each series by one.
private void chartTimer_Tick(object sender, EventArgs e)
{
if (seriesBps.Points.Count() > 300)
seriesBps.Points.RemoveAt(0);
seriesBps.Points.Add(wf.BitsPerSecond * 0.000001);
DataPoint _point1 = default(DataPoint);
foreach (DataPoint item in chart1.Series[0].Points)
{
item.Label = "";
item.MarkerStyle = MarkerStyle.None;
}
chart1.Series[0].LegendText = (wf.BitsPerSecond * 0.000001).ToString("#,##0");
DataPoint Point1 = chart1.Series[0].Points[chart1.Series[0].Points.Count - 1];
Point1.Label = chart1.Series[0].Name;
chart1.Series[0].SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes;
chart1.Series[0].SmartLabelStyle.IsMarkerOverlappingAllowed = false;
chart1.Series[0].SmartLabelStyle.MovingDirection = LabelAlignmentStyles.BottomRight;
// --------------------------------------------------------------------------------------------------- //
if (seriesPps.Points.Count() > 300)
seriesPps.Points.RemoveAt(0);
seriesPps.Points.Add(wf.PacketsPerSecond);
DataPoint _point = default(DataPoint);
foreach (DataPoint item in chart1.Series[2].Points)
{
item.Label = "";
item.MarkerStyle = MarkerStyle.None;
}
chart1.Series[1].LegendText = wf.PacketsPerSecond.ToString("#,##0");
DataPoint Point = chart1.Series[1].Points[chart1.Series[1].Points.Count - 1];
Point.Label = chart1.Series[1].Name;
chart1.Series[1].SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes;
chart1.Series[1].SmartLabelStyle.IsMarkerOverlappingAllowed = false;
chart1.Series[1].SmartLabelStyle.MovingDirection = LabelAlignmentStyles.BottomRight;
chart1.ResetAutoValues();
}
I had the same problem, for me the answer was to first clear the series like this:
_chart.Series.Clear()
This is important if you build your Charts dynamically