Hi,
As the title suggests, I need some help graphing some data from a multidimensional array using ZedGraph. Please see the following code:
int counter = 0
double [] y;
double [] x;
y = new double[FinalArray.GetLength(1) * LoopingValue];
x = new double[FinalArray.GetLength(1) * LoopingValue];
ExperimentArray[ LoopingValue, FinalArray.GetLength(1);
private void Plot_Click(object sender, EventArgs e)
{
for (int j = 0; j < LoopingValue; j ++)
{
for (int i = 0; i < FinalArray.GetLength(1); i++)
{
y[counter] = FinalArray[0, i];
x[counter] = j + 1;
counter = counter + 1;
}
}
counter = 0;
CreateGraph(zg1);
}
private void CreateGraph(ZedGraphControl zgc)
{
zg1.GraphPane.CurveList.Clear();
GraphPane mypane = zg1.GraphPane;
mypane.Title.Text = "Model Simulation";
mypane.XAxis.Title.Text = "Mass";
mypane.YAxis.Title.Text = "Force (Newtons)";
mypane.YAxis.MajorGrid.IsVisible = true;
BarItem mybar;
for (int i = 0; i < FinalArray.GetLength(1); i++)
{
mybar = mypane.AddBar(i.ToString(), x, y, Color.Blue);
}
mypane.BarSettings.Type = BarType.Stack;
mypane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45F);
mypane.Fill = new Fill(Color.White, Color.White, 45F);
zgc.AxisChange();
zg1.Refresh();
}
}
Now while this code does graph the data, it is not exactly what I am after. The array titled X has values such as the following:
X = [1,1,1,2,2,2,3,3,3,4,4,4,5,5,5]
and the array Y has (corresponding) values:
Y = [10,12,15,24,28,26,39,40,56,89,78,90,113,119,124]
so what I am after is a stacked bar chart with the 3 different values of Y, plotted at the points of X. Now I could set up 3 different arrays and blot the bars in the following manner to achieve what I want to achieve:
y1 = [10 , 24 , 39 , 89 , 113 ]
y2 = [ 12 , 28 , 40 , 78 , 119 ]
y3 = [ 15, 26 , 56 , 90 , 124]
mybar = mypane.AddBar("1", null, y1, Color.Red);
mybar = mypane.AddBar("2", null, y2, Color.Blue);
mybar = mypane.AddBar("3", null, y3, Color.Green);
but I would like to avoid hardcoding because the number of elements can potentially change depending on how the user of the application defines them eariler. i.e. I could have 50 points different arrays (y4, y5, y......, y50) to plot. So is there any way I could plot what it is I want without hardcoding? The problem lies in creating the arrays y4,y5,y6,...y100........ect, and being able to call them in a single .AddBar line. If there is a way to do this, can I also do something with the last argument in the .AddBar line so that the color is different for each stacked bar I want to plot?
Thanks for any help anyone can give me.