private void UpdateChartControlSlice(byte[] data)
{
DataTable chartdt = new DataTable();
chartdt.Columns.Add("X", Type.GetType("System.Double"));
chartdt.Columns.Add("Y", Type.GetType("System.Double"));
double valcount = 0;
int offsetinmap = (int)trackBarControl1.Value;
try
{
labelControl9.Text = X_axis_name + " [" + x_axisvalues.GetValue((int)trackBarControl1.Value).ToString() + "]";
}
catch (Exception E)
{
Console.WriteLine("value: " + (int)trackBarControl1.Value + " " + E.Message);
}
int numberofrows = data.Length / m_TableWidth;
if (m_issixteenbit)
{
numberofrows /= 2;
offsetinmap *= 2;
}
if (m_issixteenbit)
{
for (int t = (numberofrows - 1); t >= 0; t--)
{
double yval = valcount;
double value = Convert.ToDouble(data.GetValue(offsetinmap + (t * (m_TableWidth * 2)))) * 256;
value += Convert.ToDouble(data.GetValue(offsetinmap + (t * (m_TableWidth * 2)) + 1));
if (value > 32000)
{
value = 65536 - value;
value = -value;
}
value *= correction_factor;
value += correction_offset;
//value = ConvertForThreeBarSensor(value);
if (y_axisvalues.Length > valcount) yval = Convert.ToDouble((int)y_axisvalues.GetValue((int)valcount));
chartdt.Rows.Add(yval, value);
valcount++;
}
}
else
{
for (int t = (numberofrows - 1); t >= 0; t--)
{
double yval = valcount;
double value = Convert.ToDouble(data.GetValue(offsetinmap + (t * (m_TableWidth))));
value *= correction_factor;
value += correction_offset;
//value = ConvertForThreeBarSensor(value);
if (y_axisvalues.Length > valcount) yval = Convert.ToDouble((int)y_axisvalues.GetValue((int)valcount));
chartdt.Rows.Add(yval, value);
valcount++;
}
}
//chartControl1.Series[0].Label.Text = m_map_name;
/*chartControl1.Series[0].LegendText = m_map_name;
chartControl1.DataSource = chartdt;
//chartControl1.Series[0].PointOptions.PointView = PointView.ArgumentAndValues;
chartControl1.Invalidate();*/
NChart chart = nChartControl2.Charts[0];
//NSeries series = (NSeries)chart.Series[0];
NSmoothLineSeries line = null;
if (chart.Series.Count == 0)
{
line = (NSmoothLineSeries)chart.Series.Add(SeriesType.SmoothLine);
}
else
{
line = (NSmoothLineSeries)chart.Series[0];
}
// set length of axis
//NStandardScaleConfigurator scaleConfiguratorX = (NStandardScaleConfigurator)chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
//scaleConfiguratorX.MajorTickMode = MajorTickMode.AutoMaxCount;
//NScaleTitleStyle titleStyleX = (NScaleTitleStyle)scaleConfiguratorX.Title;
//titleStyleX.Text = m_y_axis_name;
//<GS-08032010> as waarden nog omzetten indien noodzakelijk (MAP etc)
//scaleConfiguratorX.AutoLabels = true;
//series.HorizontalAxes = y_axisvalues;
//scaleConfiguratorX.Labels.Clear();
/*for (int t = y_axisvalues.Length - 1; t >= 0; t--)
{
string yvalue = y_axisvalues.GetValue(t).ToString();
if (m_y_axis_name == "MAP" || m_y_axis_name == "Pressure error (bar)")
{
try
{
float v = (float)Convert.ToDouble(yvalue);
if (m_viewtype == ViewType.Easy3Bar)
{
v *= 1.2F;
}
else if (m_viewtype == ViewType.Easy35Bar)
{
v *= 1.4F;
}
else if (m_viewtype == ViewType.Easy4Bar)
{
v *= 1.6F;
}
v *= (float)0.01F;
if (m_y_axis_name == "MAP")
{
v -= 1;
}
yvalue = v.ToString("F2");
}
catch (Exception cE)
{
Console.WriteLine(cE.Message);
}
}
scaleConfiguratorX.Labels.Add(yvalue);
Console.WriteLine("Added axis label: " + yvalue);
}*/
line.ClearDataPoints();
foreach (DataRow dr in chartdt.Rows)
{
//<GS-09032010> fill second 2d chart here
//series.Values.Add(dr["Y"]);
line.AddDataPoint(new NDataPoint(Convert.ToDouble(dr["X"]), Convert.ToDouble(dr["Y"])));
//Console.WriteLine("Added value: " + dr["Y"].ToString());
}
nChartControl2.Refresh();
}