i need to write 27 line of string into notepad. and my progressbar1 used to count current line that being processed
void WriteOutput(string dir, List<String>listeksnya)
{
string outputdirectory = Path.GetDirectoryName(textBox1.Text);
string filename = Path.GetFileNameWithoutExtension(textBox1.Text);
string filenameextension = Path.GetFileName(textBox1.Text);
string newfilename = outputdirectory + "\\[Pichernenko.web.id] Output - " + filenameextension;
progressBar1.Maximum = listeksnya.Count;
//MessageBox.Show("minimum is "+progressBar1.Minimum.ToString()+" maximum is "+progressBar1.Maximum);
try
{
streamwriternya = new StreamWriter(newfilename);
for (int i = 0; i < progressBar1.Maximum+1; i++)
{
MessageBox.Show(listeksnya.ElementAt(i));
progressBar1.Value = i;
}
}
catch (Exception ex)
{
cmd.cetakGagal(ex.ToString());
}
}
i don't write to notepad, because there's a error in my progressbar , it said index was out of range
i have set the maximum value of progressbar and i want to progressbar is filled completely while MessageBox.Show(listeksnya.ElementAt(i)); processed the last element.
how do i resolve this ?
update :
i've found the answer by changing the following line
progressBar1.Maximum = listeksnya.Count-1;
The problem is with your termination condition of the for loop:
for (int i = 0; i < progressBar1.Maximum+1; i++)
Which makes you access the list's element up to progressBar1.Maximum (likely 100) while you only have 27 elements and thus producing out of range error.
Note also that C# indexing starts from 0, thus if you have 10 items in the list, you could get the element from index 0 to index 9, not from index 0 to index 10 (which makes it having 11 elements instead of 10)
MessageBox.Show(listeksnya.ElementAt(i)); //will be error from i = 27 onwards
If you want to show the progress bar as many as the file numbers which have been processed, try to normalize the value:
for (int i = 0; i < progressBar1.Maximum+1; i++)
{
MessageBox.Show(listeksnya.ElementAt(i));
double val = (i + 1) * 100d / listeksnya.Count; //note the d to avoid
progressBar1.Value = (int)val; //this is correct now, cast to int if necessary
}
And note that you have to set your loop termination as many as listeksnya.Count element instead of following the progressBar1.Maximum:
for (int i = 0; i < listeksnya.Count; ++i)
Related
I'm making console c# app that actually takes all lines from text1 and append to it in the end of each line a text that is ".php?" or ".html? and these texts are also lines from text2, I want to print the first one in text2 in the end of each line in text1. Then take the second one in text2 and do the same Until it finishes text2?
Here's my code:
string[] resultConfig = File.ReadAllLines("keywords.txt");
string[] readParameters = File.ReadAllLines("param.txt");
for (int i = 0; i < readParameters.Length; i++)
{
for (int x = 0; x < resultConfig.Length ; x++)
{
resultConfig[x] = resultConfig[x] + readParameters[i];
Console.WriteLine(resultConfig[x]);
}
}
OUTPUT:
**
keyboards.php?.html?.asp?
karachi.php?.html?.asp?
keychain.php?.html?.asp?
in khobar.php?.html?.asp?
lebanon.php?.html?.asp?
lights.php?.html?.asp?
london.php?.html?.asp?
must have.php?.html?.asp?
**
**
WHAT IT SHOULD BE:
keyboards.php?
karachi.php?
keychain.php?
in khobar.php?
lebanon.php?
lights.php?
london.php?
must have.php?
keyboards.html?
karachi.html?
keychain.html?
in khobar.html?
lebanon.html?
lights.html?
london.html?
must have.html?
**
etc...
** KEYWORDS.TXT CONTAINS **
keyboards
karachi
keychain
in khobar
lebanon
lights
london
must have
** PARAM.TXT CONTAINS **
.php?
.asp?
.html?
Your problem is this line resultConfig[x] = resultConfig[x] + readParameters[i];. In this line you change your string in resultConfig[x] and since you're using a nested loop, this happens for every line in your *param.txt` file.
In order to write you desired result in the console try this code instead:
string[] resultConfig = File.ReadAllLines("keywords.txt");
string[] readParameters = File.ReadAllLines("param.txt");
for (int i = 0; i < readParameters.Length; i++)
{
for (int x = 0; x < resultConfig.Length ; x++)
{
string line = resultConfig[x] + readParameters[i];
Console.WriteLine(line);
}
}
You keep adding the parameter to the config and you should change the order of the loops and not change the value in the array.
Something like this:
string[] resultConfig = File.ReadAllLines("keywords.txt");
string[] readParameters = File.ReadAllLines("param.txt");
for (int x = 0; x < resultConfig.Length ; x++)
{
for (int i = 0; i < readParameters.Length; i++)
{
Console.WriteLine(resultConfig[x] + readParameters[i]);
}
}
It appears you want to save all these results in the resultConfig array, but you can't just add more items to an array than it was initialized with - you have to resize it first using Array.Resize(ref resultConfig, resultConfig.Length * readParameters.Length).
However, even then it will be a little tricky to append to the first set of items and then add new items for the additional parameters (it can be done if that's really necessary).
Instead I would create a new List<string> to save the results, and leave the initial arrays as they are:
string[] resultConfig =
{
"keyboards",
"karachi",
"keychain",
"in khobar",
"lebanon",
"lights",
"london",
"must have"
};
string[] readParameters = {".php?", ".html?", ".asp?"};
var allCombinations = new List<string>();
for (int i = 0; i < readParameters.Length; i++)
{
for (int x = 0; x < resultConfig.Length; x++)
{
allCombinations.Add(resultConfig[x] + readParameters[i]);
Console.WriteLine(resultConfig[x] + readParameters[i]);
}
}
I've been trying to display all the pair numbers in a loop that goes from 1 to 100 and increments 1 each time. I try to display the pair numbers like they would in this "if" code block.
for (var i = 0; i < 100; i++)
{
if (i % 2 == 0)
{
Console.WriteLine(i);
}
But I want to save these in a string called "losPares", which I attempt to do display in this way:
static void Main(string[] args)
{
var counter = 0;
var losPares = 0;
for (var i = 0; i < 100; i++)
{
if (i % 2 == 0)
{
counter++;
losPares = i;
}
}
Console.WriteLine("hay " + counter + " numeros pares.");
Console.WriteLine("estos son " + losPares);
}
Which is kinda weird. In the first code example the console will print out all the pair numbers. In the second one it will only print the last of them, 98. I don't really know what to do, tried creating an array instead of a variable but when I try to store "i" in it i get the following error:
Cannot implicitly convert type 'int' to 'int[]'
aAd if i try to cast "i" as a string when losPares is an array instead of a variable, like this:
int[] losPares = new int[100];
for (var i = 0; i < 100; i++)
{
if (i % 2 == 0)
{
counter++;
losPares = Convert.ToBase64CharArray(i);
}
I get the following error.
CS1501 No overload for method 'ToBase64CharArray' takes 1 arguments
I don't really know what to do. Thanks a bunch for reading!
Your console is printing last element because you are assigning value of i to losPares in your sencond code snippet. This assignment operator assinging value of i to losPares in each iteration where i % 2 condition is satisfied.
Instead of assigning value to integer, use List to store i and at the end of for loop print all elements from list.
public static void Main(string[] args)
{
var losPares = List<int>();
var counter = 0;
for (var i = 0; i < 100; i++)
{
if (i % 2 == 0)
{
counter++;
//Below line was executing everytime and in each execution this line was assigning value of i to losPares
//losPares = i;
losPares.Add(i);
}
}
Console.WriteLine("hay " + counter + " numeros pares.");
Console.WriteLine("estos son " + string.Join(Environment.NewLine, losPares));
}
An integer will only have 1 value and cannot have multiple values at the same time. If you want to keep track of all the values from the loop, you will have to save all the values in a collection / list or an array. Following example shows how to save them in a List.
var counter = 0;
var losPares = new List<int>();
for (var i = 0; i < 100; i++)
{
if (i % 2 == 0)
{
counter++;
losPares.Add(i);
}
}
Console.WriteLine("hay " + counter + " numeros pares.");
Console.WriteLine("estos son " + string.Join(" ", losPares));
You can create a list of ints (losPares) and then display that at the end. What you are doing is assigning a value to losPares and then overriding it again and again until the last iteration in you loop. That is why your losPares always have the last value.
As per my understanding below are my takes. First one is printing all values because the printing part is inside the loop but in second both print statements are outside the for loop block because of which it stores the last value of loop and display it.
You can create a string variable and append all the numbers to that string.
string temp = ''; and then in for loop you can do something like temp+=i + ' '; It is better to use string builder because of immutable property of string.
If you want to use array. Below is the way to assign values in a array.
int[] losPares = new int[100];
In a for loop you can use losPares[i] = i; This will fill your array.
this is my very first post here on StackOverflow so please tell me if I did anything wrong, also english is not my native language, forgive me if there is any gramatical errors.
My question is how can I permutate the items of an array of type "Location", I need to get all possible permutations of waypoints given by the user to then calculate the best route based on time or distance. (I don't want to use the normal route calculation)
I've searched for algorithms but all of them when I put the array of type "Location[]" in the function's parameter I get the error that the object needs to be IEnumerable and I don't know how to convert to that if is even possible, I never worked with IEnumerable.
If it is of any help this is my code for calculating the route:
//Gets the waypoints from a listBox provided by the user, "mode" selects between best time and best distance
//backgroundworker so the UI dont freezes, and return the optimal waypoint order
public Location[] CalcularRota(Location[] waypoints, int mode, BackgroundWorker work, DoWorkEventArgs e)
{
//Declarations
string origem = "";
string destino = "";
Rota[] prop = new Rota[100]; //this index is the number of times the algorithm will be executed, more equals accuracy but much more time to complete
Rota bestDist = new Rota();
Rota bestTime = new Rota();
DirectionService serv = new DirectionService();
DirectionRequest reqs = new DirectionRequest();
DirectionResponse resp;
Random rnd = new Random();
Location[] rndWays;
int dist = 0;
int ti = 0;
bestDist.Distance = 1000000000; //put higher values for the first comparation to be true (end of code)
bestTime.Time = 1000000000;
if (waypoints != null)
{
reqs.Sensor = false;
reqs.Mode = TravelMode.driving;
for (int i = 0; i < prop.Length; i++) //initializes prop
prop[i] = new Rota();
for (int i = 0; i < prop.Length; i++)
{
rndWays = waypoints.OrderBy(x => rnd.Next()).ToArray(); //randomizes the order, I want to get all permutations and then test
//but I dont know how so I've been using randomized
dist = ti = 0;
origem = prop[0].ToString(); //save this particular waypoint's origin and destination
destino = prop[1].ToString();
reqs.Origin = origem;
reqs.Destination = destino;
if (waypoints.Length > 0)
reqs.Waypoints = rndWays;
resp = serv.GetResponse(reqs); //request the route with X order of waypoints to google
if (resp.Status == ServiceResponseStatus.Ok) //wait the response otherwise the program crashes
{
for (int j = 0; j < resp.Routes[0].Legs.Length; j++) //gets the distance and time of this particular order
{
ti += int.Parse(resp.Routes[0].Legs[j].Duration.Value);
dist += int.Parse(resp.Routes[0].Legs[j].Distance.Value);
}
}
prop[i].Origem = origem; //saves this waypoints order details for further comparison
prop[i].Destino = destino;
prop[i].Distance = dist;
prop[i].Time = ti;
prop[i].Order = rndWays;
work.ReportProgress(i); //report the progress
}
for (int i = 0; i < prop.Length; i++) //gets the best distance and time
{
if (bestDist.Distance > prop[i].Distance)
{
bestDist.Distance = prop[i].Distance;
bestDist.Time = prop[i].Time;
bestDist.Order = prop[i].Order;
bestDist.Origem = prop[i].Origem;
bestDist.Destino = prop[i].Destino;
}
if (bestTime.Time > prop[i].Time)
{
bestTime.Distance = prop[i].Distance;
bestTime.Time = prop[i].Time;
bestTime.Order = prop[i].Order;
bestTime.Origem = prop[i].Origem;
bestTime.Destino = prop[i].Destino;
}
}
if (bestDist.Order == bestTime.Order) //if the same waypoint order has the same time and distance
return bestDist.Order; // returns whatever bestDist.Order or bestTime.Order
else if (bestDist.Order != bestTime.Order) //if different returns corresponding to the mode selected
{
if (mode == 1) return bestDist.Order;
if (mode == 2) return bestTime.Order;
}
}
return null;
}
What I want is to permutate the waypoints given and test each permutation, I've been struggling with this for a time, if u guys could help me with any way possible would be great.
Ty.
EDIT.
I found this function here on StackOverflow:
public static bool NextPermutation<T>(T[] elements) where T : IComparable<T>
{
var count = elements.Length;
var done = true;
for (var i = count - 1; i > 0; i--)
{
var curr = elements[i];
// Check if the current element is less than the one before it
if (curr.CompareTo(elements[i - 1]) < 0)
{
continue;
}
// An element bigger than the one before it has been found,
// so this isn't the last lexicographic permutation.
done = false;
// Save the previous (bigger) element in a variable for more efficiency.
var prev = elements[i - 1];
// Have a variable to hold the index of the element to swap
// with the previous element (the to-swap element would be
// the smallest element that comes after the previous element
// and is bigger than the previous element), initializing it
// as the current index of the current item (curr).
var currIndex = i;
// Go through the array from the element after the current one to last
for (var j = i + 1; j < count; j++)
{
// Save into variable for more efficiency
var tmp = elements[j];
// Check if tmp suits the "next swap" conditions:
// Smallest, but bigger than the "prev" element
if (tmp.CompareTo(curr) < 0 && tmp.CompareTo(prev) > 0)
{
curr = tmp;
currIndex = j;
}
}
// Swap the "prev" with the new "curr" (the swap-with element)
elements[currIndex] = prev;
elements[i - 1] = curr;
// Reverse the order of the tail, in order to reset it's lexicographic order
for (var j = count - 1; j > i; j--, i++)
{
var tmp = elements[j];
elements[j] = elements[i];
elements[i] = tmp;
}
// Break since we have got the next permutation
// The reason to have all the logic inside the loop is
// to prevent the need of an extra variable indicating "i" when
// the next needed swap is found (moving "i" outside the loop is a
// bad practice, and isn't very readable, so I preferred not doing
// that as well).
break;
}
// Return whether this has been the last lexicographic permutation.
return done;
}
The usage is:
NextPermutation(array);
Doing this and putting my array (rndWays) as overload I get the following error:
The type 'Google.Maps.Location' cannot be used as type parameter 'T' in the generic type or method 'Form1.NextPermutation< T >(T[])'. There is no implicit reference conversion from 'Google.Maps.Location' to 'System.IComparable< Google.Maps.Location >'.
The problem is that Location does not implement the IComparable interface.
Change:
public static bool NextPermutation<T>(T[] elements) where T : IComparable<T>
to:
public static bool NextPermutation(Location[] elements)
And replace each CompareTo() with your own comparison function.
So I've been woking a Console game for a while now and I desided to use .txt files to hold the maps. This code opens and stores the txt file contents:
static void LoadMap(string fname)
{
string _org = File.ReadAllText("Maps/" + fname + ".txt");
_org.Split(',');
string[] _tmp = new string[_org.Length];
for (int i=0;i<_org.Length;i++)
{
_tmp[i] = _org[i].ToString();
}
//This line has the error
for (int i=0;_tmp[i]!="$";i+=2)
{
mapwidth += 1;
}
for (int i=0;i<_tmp.Length;i++)
{
leveldata.Add(_tmp[i]);
}
}
I get this error: Index was outside the bounds of the array. I can't figgure out why. Can anyone help? Thanks
Check that variable i does not take values beyond the Length - 1 of the array.
static void LoadMap(string fname)
{
string _org = File.ReadAllText("Maps/" + fname + ".txt");
_org.Split(',');
string[] _tmp = new string[_org.Length];
for (int i = 0;i < _org.Length; i++)
{
_tmp[i] = _org[i].ToString();
}
for (int i = 0;i < _tmp.Length && _tmp[i] != "$"; i += 2)
{
mapwidth += 1;
}
for (int i = 0;i < _tmp.Length; i++)
{
leveldata.Add(_tmp[i]);
}
}
I am not super sure what you are getting at here but I feel a foreach may be a step in the right direction.
First, here are a few things I noticed in the code you presented.
string _org = File.ReadAllText("Maps/" + fname + ".txt");
_org.Split(',');
Here you have ingested your text file and split _org with a comma delimiter. Though you never actually assigned the split array to a variable. _org is still a string, not a string[].
string[] _tmp = new string[_org.Length];
for (int i = 0; i < _org.Length; i++)
{
_tmp[i] = _org[i].ToString();
}
In this block we have set _tmp as a string array using the length of _org. The Length property in this case will retrieve the number of characters in the string _org. assuming _org is set to "foo" the size of the _tmparray is now 3. (0,1,2)
You then go on to load _tmp with the nth character of _org converted to a string.
At this point we have the following in our variables.
_org = "foo"
_tmp = {"f","o","o"}
This next part caught me a bit off guard as I cant tell for certain what you are trying to accomplish.
for (int i = 0; _tmp[i] != "$"; i += 2)
{
mapwidth += 1;
}
You are in a for loop until _tmp[i] equals "$", and you are adding 2 to i every time you move through the loop using i += 2. This logic will break the loop until it hits a "$", or if i grows outside of the bounds of the array it will throw an exception.
You then go on to add one to the mapwidth for every two increments of i
In this final block you are adding the contents of the _tmp array to leveldata
for (int i = 0; i < _tmp.Length; i++)
{
leveldata.Add(_tmp[i]);
}
Now for the good stuff, foreach.
I have made the assumption you wanted to set _org as an array, and that you wanted everything that was not a "$". That in mind, this should accomplish what you were going for, though I am not sure the purpose of incrementing by 2 in the second for loop so I have left that out for now.
static void LoadMap(string fname)
{
string[] _org = File.ReadAllText("Maps/" + fname + ".txt").Split(',');
foreach (var _tmp in _org)
{
if (_tmp != "$")
{
mapwidth += 1;
}
leveldata.Add(_tmp);
}
}
If you want to continue coding it is always a good idea to get a good grasp on the basics.
Though a bit dated here is a good tutorial by Microsoft for programming basics in C#:
C# Programmer's Reference
Try this link.
https://www.programiz.com/csharp-programming/foreach-loop
Have suggestion keyword to avoid Index was outside the bounds of the array error.
Sample code.
for(int i = 0; i < myArray.Length; i++)
{
// Coding to Array for loop.
}
I have an asp:Chart control and it is working great. I simply am passing it times (in millitary format) and then values that are average length in time of requests. The following code does what I need - almost (feel free to mark it up if I am going overboard for I am new to the chart control).
My data is in table for like the following:
Date by Hours 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00
12/03/2010 8 43 53 55 33 46 51 60 50 9
Friday 1.773 1.337 1.242 1.239 1.340 1.191 1.479 1.223 1.178 1.516
Gives me a nice chart. My question is below this code:
List<double> yValues = new List<double>();
List<string> xValues = new List<string>();
// First and Last columns do not contain chartable data
for (int i = 1; i < dtResults.Columns.Count - 1; i++) {
double d;
if (double.TryParse(dtResults.Rows[1][i].ToString(), out d))
yValues.Add(d == 0 ? double.NaN : d);
else
yValues.Add(double.NaN);
} // foreach of the Average Time Values the chart
// foreach of the column names
for (int i = 1; i < dtResults.Columns.Count - 1; i++)
xValues.Add(dtResults.Columns[i].ColumnName);
this.Chart.Titles["Title1"].Text = string.Format(
"Average Request Time In Seconds On {0:MM/dd/yyyy} Between {1:HH} and {2:HH} In {3}",
this.DateRange.BeginDate.Value,
this.ucsTimePicker.BeginTime,
this.ucsTimePicker.EndTime,
this.SelectedSourceEnvironmentName
);
this.Chart.Series["Series1"].Points.DataBindXY(xValues, yValues);
this.Chart.Series["Series1"].ChartType = SeriesChartType.Line;
this.Chart.Series["Series1"].IsValueShownAsLabel = true;
this.Chart.Series["Series1"]["ShowMarkerLines"] = "true";
this.Chart.Series["Series1"].Label = "#VALY{0.000}"; // Make sure they have only 3 decimal places
this.Chart.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true;
this.Chart.ChartAreas["ChartArea1"].AxisX.Title = "Hours of the Day";
this.Chart.ChartAreas["ChartArea1"].AxisY.Title = "Time in Seconds";
// Handle styling when there is a Zero or missing value
this.Chart.Series["Series1"].EmptyPointStyle.Color = Color.Red;
this.Chart.Series["Series1"].EmptyPointStyle.BorderWidth = 3;
this.Chart.Series["Series1"].EmptyPointStyle.BorderDashStyle = ChartDashStyle.Dash;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerStyle = MarkerStyle.Diamond;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerColor = Color.Red;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerSize = 8;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerBorderColor = Color.Black;
this.Chart.Series["Series1"]["EmptyPointValue"] = "Zero";
There are labels showing (the decimal numbers in the table above) but what I want to do is have the label Also show the total number of requests which is the 2nd row of data in the table above. I was able to add the values to the chart with the code below:
for (int i = 1; i < dtResults.Columns.Count - 1; i++) {
int n;
if (int.TryParse(dtResults.Rows[0][i].ToString(), out n))
this.Chart.Series["Series1"].Points.AddY(n);
else
this.Chart.Series["Series1"].Points.AddY(0);
} // foreach of the Count of Request within the Hour values
That seemed to not throw any fits, but I couldn't access the values with the following adjustment:
this.Chart.Series["Series1"].Label = "#VALY{0.000}\n#VALY2{0}";
All I get is the original value (1.773) showing up twice.
So is there a way to add data to a Chart that is only for labeling purposes and then access it?
Okay, after no help here (which actually shocks me) I was able to figure it out with some help outside of this site. Essentially, I don't have to Add the "extra" data but I do have to modify each Label as opposed to just having the generic label like the following:
this.Chart.Series["Series1"].Label = "#VALY{0.000}"; // Make sure they have only 3 decimal places
I also had to take out the following line:
this.Chart.Series["Series1"].IsValueShownAsLabel = true;
So just for brevity, here is the entire code giving me the two line label where the first line shows the average (which is the actual chart data) and the second line is the count which is not in the data at all.
List<double> yValues = new List<double>();
List<string> xValues = new List<string>();
List<int> zValues = new List<int>();
// First and Last columns do not contain chartable data
for (int i = 1; i < dtResults.Columns.Count - 1; i++) {
double d;
if (double.TryParse(dtResults.Rows[1][i].ToString(), out d))
yValues.Add(d == 0 ? double.NaN : d);
else
yValues.Add(double.NaN);
} // foreach of the Average Time Values the chart
// foreach of the column names
for (int i = 1; i < dtResults.Columns.Count - 1; i++)
xValues.Add(dtResults.Columns[i].ColumnName);
this.Chart.Titles["Title1"].Text = string.Format(
"Average Request Time In Seconds On {0:MM/dd/yyyy} Between {1:HH} and {2:HH} In {3}",
this.DateRange.BeginDate.Value,
this.ucsTimePicker.BeginTime,
this.ucsTimePicker.EndTime,
this.SelectedSourceEnvironmentName
);
this.Chart.Series["Series1"].Points.DataBindXY(xValues, yValues);
/// This loop will setup the point labels in a two line format where the first line displays
/// the Average that the point is actually showing. The second line is data taken from the
/// results table and is not a part of the chart at all but is useful information and is the
/// Count of records in that time frame.
/// In order for this to work, the Series property IsValueShownAsLabel needs to be NOT True.
for (int i = 0; i < this.Chart.Series["Series1"].Points.Count; i++) {
int n = 0;
int.TryParse(dtResults.Rows[0][i + 1].ToString(), out n);
this.Chart.Series["Series1"].Points[i].Label = string.Format("Avg: #VALY{{0.000}}\nCount: {0}", n);
} // foreach of the Count of Request within the Hour values
this.Chart.Series["Series1"].ChartType = SeriesChartType.Line;
this.Chart.Series["Series1"]["ShowMarkerLines"] = "true";
this.Chart.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true;
this.Chart.ChartAreas["ChartArea1"].AxisX.Title = "Hours of the Day";
this.Chart.ChartAreas["ChartArea1"].AxisY.Title = "Time in Seconds";
// Handle styling when there is a Zero or missing value
this.Chart.Series["Series1"].EmptyPointStyle.Color = Color.Red;
this.Chart.Series["Series1"].EmptyPointStyle.BorderWidth = 3;
this.Chart.Series["Series1"].EmptyPointStyle.BorderDashStyle = ChartDashStyle.Dash;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerStyle = MarkerStyle.Diamond;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerColor = Color.Red;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerSize = 8;
this.Chart.Series["Series1"].EmptyPointStyle.MarkerBorderColor = Color.Black;
this.Chart.Series["Series1"]["EmptyPointValue"] = "Zero";