Hi,
Here is the code snippet to set up the chart. The input dataset has 3 columns named, "X", "Y" and "Data", having values as per my previous post.
Thanks for your guidance on this.
public
void PlotChart(DataSet inputDataset, string dataTableName, string[] xList, string[] yList)
{
//private Xceed.Chart.ChartControl chartControl1; -- Added to the Form in design view
Xceed.Chart.Core.
Chart _chart = this.chartControl1.Charts[0];
Xceed.Chart.Core.
GridSurfaceSeries _surfaceSeries = (Xceed.Chart.Core.GridSurfaceSeries)_chart.Series[0];
_surfaceSeries.Data.Clear();
_surfaceSeries.Data.SetGridSize(xList.Length, yList.Length);
double max = double.MinValue;
double min = double.MaxValue;
// PLOT points
for (int series = 0; series < yList.Length; series++)
{
string yLabel = yList[series];
for (int point = 0; point < xList.Length; point++)
{
string xLabel = xList[point];
DataRow[] rows = inputDataset.Tables[dataTableName].
Select(
"X = '" + xLabel + "' AND Y='" + yLabel + "'");
if (rows.Length > 0)
{
double value = (double)rows[0]["Data"];
if ((double)rows[0]["Data"] > max)
max = (
double)rows[0]["Data"];
if ((double)rows[0]["Data"] < min)
min = (
double)rows[0]["Data"];
_surfaceSeries.Data.SetValue(point, yList.Length - series - 1, value);
}
else
_surfaceSeries.Data.SetValue(point, yList.Length - series - 1,
DBNull.Value);
}
}
// INIT legend
_surfaceSeries.AutomaticPalette =
false;
_surfaceSeries.Palette.Clear();
Color[] colors = new Color[]
{
Color.DarkBlue,
Color.Blue,
Color.DeepSkyBlue,
Color.Cyan,
Color.Green,
Color.YellowGreen,
Color.Yellow,
Color.Gold,
Color.Orange,
Color.Red,
Color.DarkRed
};
max =
Math.Ceiling(max * 100d) / 100d; // Take ceiling to include MAX point
min =
Math.Floor(min * 100d) / 100d; // Take floor to include MIN point
for (int i = colors.Length - 1; i >= 0; i--)
{
double increment = (max - min) / 10d;
_surfaceSeries.Palette.Add(
Math.Round(min + i * increment, 2), colors[ i ]);
}
// INIT Axis
_surfaceSeries.PaletteFrame =
false;
_surfaceSeries.FrameLine.Color =
Color.Black;
_surfaceSeries.FrameLine.Pattern = Xceed.Chart.GraphicsCore.
LinePattern.Solid;
_surfaceSeries.FrameLine.Width = 1;
_surfaceSeries.FrameStyle = Xceed.Chart.Core.
SurfaceFrameStyle.MeshContour;
_surfaceSeries.FillStyle = Xceed.Chart.Core.
SurfaceFillStyle.Zone;
_surfaceSeries.SmoothPalette =
false;
_surfaceSeries.Legend.Format =
"<zone_begin> - <zone_end>";
_chart.Axis(Xceed.Chart.Core.
StandardAxis.PrimaryX).Labels.Clear();
for (int point = 0; point < xList.Length; point++)
_chart.Axis(Xceed.Chart.Core.
StandardAxis.PrimaryX).Labels.Add(xList[point]);
_chart.Axis(Xceed.Chart.Core.
StandardAxis.Depth).Labels.Clear();
for (int series = 0; series < yList.Length; series++)
_chart.Axis(Xceed.Chart.Core.
StandardAxis.Depth).Labels.Add(yList[yList.Length - series - 1]);
this.chartControl1.Refresh();
}