I have a log file that contains (IP, datetime, pingtime). I read the data from the log.txt file, I group them and after that I create the chart series.
The problem: the legend shows multiple times the name of IP.
How can I correct this problem?
PS: I attached a screenshot too.
Screenshot:
https://imgur.com/a/uBEFnGJ
thanks advanced,
istvan
public void getSeries()
{
string path = mainform.path + "log.txt";
int counter = 0;
string line;
List<IPList> listIPs = new List<IPList>();
chartControlHistory.Series.Clear();
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader file = new StreamReader(fs);
while ((line = file.ReadLine()) != null)
{
System.Console.WriteLine(line);
string[] newline = line.Split(';');
if (newline.Length > 7)
{
IPList ips = new IPList();
ips.IPAddress = newline[2];
ips.datetime = Convert.ToDateTime(newline[1].ToString());
ips.pingtime = Convert.ToDouble(newline[5].ToString());
listIPs.Add(ips);
}
counter++;
}
file.Close();
var groupedList = (from s in listIPs group s by s.IPAddress.Trim() into grp where !grp.Key.Contains("IPPINGER") select grp.Key).ToList();
ChartSeries[] chartSeries = new ChartSeries[listIPs.Count];
foreach (var ips in groupedList.ToList())
{
for (int i = 0; i < listIPs.Count; i++)
{
if (ips == listIPs[i].IPAddress)
{
chartSeries[i] = new ChartSeries(listIPs[i].IPAddress, ChartSeriesType.Bubble);
chartSeries[i].Points.Add(Convert.ToDateTime(listIPs[i].datetime.ToString()), Convert.ToDouble(listIPs[i].pingtime.ToString()));
chartSeries[i].PointsToolTipFormat = "DateTime:{3}";
}
}
}
string ip = "";
foreach (var ips in groupedList.ToList())
{
foreach (ChartSeries ch in chartSeries)
{
if (ch != null)
{
chartControlHistory.Series.Add(ch);
}
}
}
this.chartControlHistory.ImprovePerformance = true;
this.chartControlHistory.CalcRegions = false;
this.chartControlHistory.NeedPerformance = true;
this.chartControlHistory.Crosshair.Visible = true;
this.chartControlHistory.PrimaryXAxis.ShowCrosshairTooltip = true;
this.chartControlHistory.PrimaryYAxis.ShowCrosshairTooltip = true;
this.chartControlHistory.Series3D = true;
this.chartControlHistory.ZoomType = ZoomType.Selection;
}