private void FillData() { int dataPointCount = 10000; int lineCount = 5; NChart chart = nChartControl1.Charts[0]; chart.Series.Clear(); Random random = new Random(); NChartPalette palette = new NChartPalette(ChartPredefinedPalette.Fresh); for (int lineIndex = 0; lineIndex < lineCount; lineIndex++) { // setup surface series NVertexSurfaceSeries surface = new NVertexSurfaceSeries(); chart.Series.Add(surface); surface.Name = "Surface"; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.FillMode = SurfaceFillMode.CustomColors; surface.FrameMode = SurfaceFrameMode.Dots; surface.FrameColorMode = SurfaceFrameColorMode.CustomColors; surface.VertexPrimitive = VertexPrimitive.LineStrip; surface.Data.UseColors = true; surface.Data.SetCapacity(dataPointCount); double x = 0.1; double y = 0; double z = 0; double a = 10.0; double b = 18 + lineIndex; // 28.0 - ; double c = (lineIndex + 3) / 3.0; //8.0 double t = lineIndex * (0.01 / lineCount) + 0.01; Color color1 = palette.SeriesColors[lineIndex % palette.SeriesColors.Count]; Color color2 = palette.SeriesColors[(lineIndex + 1) % palette.SeriesColors.Count]; for (int dataPointIndex = 0; dataPointIndex < dataPointCount; dataPointIndex++) { float xt = (float)(x + t * a * (y - x)); float yt = (float)(y + t * (x * (b - z) - y)); float zt = (float)(z + t * (x * y - c * z)); surface.Data.AddValueColor(xt, yt, zt, InterpolateColors(color1, color2, (float)((yt + 40.0) / 80.0))); x = xt; y = yt; z = zt; } } }
public override void Initialize() { base.Initialize(); nChartControl1.Settings.RenderSurface = RenderSurface.Window; nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = nChartControl1.Labels.AddHeader(""); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.TextFormat = TextFormat.XML; title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue); // setup chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 50.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); // setup axes NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator; scaleY.MajorTickMode = MajorTickMode.AutoMaxCount; scaleY.MaxTickCount = 5; NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator(); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale; linearScale = new NLinearScaleConfigurator(); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; chart.Axis(StandardAxis.Depth).ScaleConfigurator = linearScale; // setup surface series m_Surface = new NVertexSurfaceSeries(); chart.Series.Add(m_Surface); m_Surface.Name = "Surface"; m_Surface.SyncPaletteWithAxisScale = false; m_Surface.PaletteSteps = 8; m_Surface.ValueFormatter.FormatSpecifier = "0.00"; m_Surface.FillMode = SurfaceFillMode.ZoneTexture; m_Surface.ShadingMode = ShadingMode.Smooth; m_Surface.SmoothPalette = true; // apply layout ConfigureStandardLayout(chart, title, null); VertexPrimitiveCombo.FillFromEnum(typeof(VertexPrimitive)); VertexPrimitiveCombo.SelectedIndex = (int)VertexPrimitive.Points; }
private void UpdateData() { NChart chart = nChartControl1.Charts[0]; chart.Series.Clear(); Random random = new Random(); // setup surface series NVertexSurfaceSeries surface = new NVertexSurfaceSeries(); chart.Series.Add(surface); surface.Name = "Surface"; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.FillMode = SurfaceFillMode.CustomColors; surface.FrameMode = SurfaceFrameMode.None; surface.VertexPrimitive = VertexPrimitive.Triangles; surface.Data.UseColors = true; surface.UseIndices = true; int cubeSide = (CubeSideSizeComboBox.SelectedIndex + 1); int dataPointCount = 8 * (int)Math.Pow(cubeSide, 3); Random rand = new Random(); surface.Data.SetCapacity(dataPointCount); uint currentIndex = 0; uint[] cubeIndices = new uint[] { // bottom 0, 1, 3, 0, 3, 2, // left 2, 0, 4, 2, 4, 6, // right 1, 3, 5, 3, 7, 5, // front 0, 1, 4, 1, 5, 4, // back 2, 6, 3, 3, 6, 7, // top 4, 5, 6, 5, 7, 6 }; // generate all vertexes and colors for (int x = 0; x < cubeSide; x++) { double x1 = x + 0.1; double x2 = x + 1 - 0.1; int r1 = (byte)(x1 * 255.0 / cubeSide); int r2 = (byte)(x1 * 255.0 / cubeSide); for (int y = 0; y < cubeSide; y++) { double y1 = y + 0.1; double y2 = y + 1 - 0.1; int g1 = (byte)(y1 * 255.0 / cubeSide); int g2 = (byte)(y1 * 255.0 / cubeSide); for (int z = 0; z < cubeSide; z++) { double z1 = z + 0.1; double z2 = z + 1 - 0.1; int b1 = (byte)(z1 * 255.0 / cubeSide); int b2 = (byte)(z1 * 255.0 / cubeSide); surface.Data.AddValueColor(new NVector3DD(x1, y1, z1), Color.FromArgb(r1, g1, b1)); surface.Data.AddValueColor(new NVector3DD(x2, y1, z1), Color.FromArgb(r2, g1, b1)); surface.Data.AddValueColor(new NVector3DD(x1, y2, z1), Color.FromArgb(r1, g2, b1)); surface.Data.AddValueColor(new NVector3DD(x2, y2, z1), Color.FromArgb(r2, g2, b1)); surface.Data.AddValueColor(new NVector3DD(x1, y1, z2), Color.FromArgb(r1, g1, b2)); surface.Data.AddValueColor(new NVector3DD(x2, y1, z2), Color.FromArgb(r2, g1, b2)); surface.Data.AddValueColor(new NVector3DD(x1, y2, z2), Color.FromArgb(r1, g2, b2)); surface.Data.AddValueColor(new NVector3DD(x2, y2, z2), Color.FromArgb(r2, g2, b2)); // add indicess for (int i = 0; i < cubeIndices.Length; i++) { surface.Indices.Add(currentIndex + cubeIndices[i]); } currentIndex += 8; } } } nChartControl1.Refresh(); }
public override void Initialize() { base.Initialize(); nChartControl1.Settings.RenderSurface = RenderSurface.Window; nChartControl1.Settings.ShapeRenderingMode = ShapeRenderingMode.HighSpeed; nChartControl1.Settings.JitterMode = JitterMode.Disabled; nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Vertex Surface Series<br/><font size='10pt'>Used to draw a pyramid that reuses vertex data to draw the side triangles.</font>"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.TextFormat = TextFormat.XML; title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue); // setup chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 50.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); // turn off lighting to improve performance chart.LightModel.EnableLighting = false; // setup axes NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator; scaleY.MajorTickMode = MajorTickMode.AutoMaxCount; scaleY.MaxTickCount = 5; NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator(); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale; linearScale = new NLinearScaleConfigurator(); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); linearScale.MajorGridStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; chart.Axis(StandardAxis.Depth).ScaleConfigurator = linearScale; // setup surface series NVertexSurfaceSeries surface = new NVertexSurfaceSeries(); chart.Series.Add(surface); surface.Name = "Surface"; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.FillMode = SurfaceFillMode.CustomColors; surface.UseIndices = true; surface.FrameMode = SurfaceFrameMode.None; surface.VertexPrimitive = VertexPrimitive.Triangles; surface.Data.UseColors = true; // top surface.Data.AddValueColor(new NVector3DD(0.5, 1, 0.5), Color.Red); surface.Data.AddValueColor(new NVector3DD(0, 0, 0), Color.Green); surface.Data.AddValueColor(new NVector3DD(1, 0, 0), Color.Green); surface.Data.AddValueColor(new NVector3DD(1, 0, 1), Color.Blue); surface.Data.AddValueColor(new NVector3DD(0, 0, 1), Color.Blue); // first triangle surface.Indices.Add(0); surface.Indices.Add(1); surface.Indices.Add(2); // second triangle surface.Indices.Add(0); surface.Indices.Add(2); surface.Indices.Add(3); // third triangle surface.Indices.Add(0); surface.Indices.Add(3); surface.Indices.Add(4); // fourth triangle surface.Indices.Add(0); surface.Indices.Add(4); surface.Indices.Add(1); // apply layout ConfigureStandardLayout(chart, title, null); }
private void UpdateData() { int dataPointCount = 0; switch (DataPointCountPerLineComboBox.SelectedIndex) { case 0: dataPointCount = 10000; break; case 1: dataPointCount = 100000; break; case 2: dataPointCount = 500000; break; } int lineCount = (int)NumberOfLinesUpDown.Value; NChart chart = nChartControl1.Charts[0]; chart.Series.Clear(); Random random = new Random(); NChartPalette palette = new NChartPalette(ChartPredefinedPalette.Fresh); for (int lineIndex = 0; lineIndex < lineCount; lineIndex++) { // setup surface series NVertexSurfaceSeries surface = new NVertexSurfaceSeries(); chart.Series.Add(surface); surface.Name = "Surface"; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.FillMode = SurfaceFillMode.CustomColors; surface.FrameMode = SurfaceFrameMode.Dots; surface.FrameColorMode = SurfaceFrameColorMode.CustomColors; surface.VertexPrimitive = VertexPrimitive.LineStrip; surface.Data.UseColors = true; surface.Data.SetCapacity(dataPointCount); double x = 0.1; double y = 0; double z = 0; double a = 10.0; double b = 18 + lineIndex; // 28.0 - ; double c = (lineIndex + 3) / 3.0; //8.0 double t = lineIndex * (0.01 / lineCount) + 0.01; NArgbColorValue color1 = new NArgbColorValue(palette.SeriesColors[lineIndex % palette.SeriesColors.Count]); NArgbColorValue color2 = new NArgbColorValue(palette.SeriesColors[(lineIndex + 1) % palette.SeriesColors.Count]); unsafe { fixed(byte *pData = &surface.Data.Data[0]) { float *pVertex = (float *)pData; uint * pColor = (uint *)(pData + surface.Data.ColorOffset * 4); for (int dataPointIndex = 0; dataPointIndex < dataPointCount; dataPointIndex++) { float xt = (float)(x + t * a * (y - x)); float yt = (float)(y + t * (x * (b - z) - y)); float zt = (float)(z + t * (x * y - c * z)); pVertex[0] = xt; pVertex[1] = yt; pVertex[2] = zt; *pColor = InterpolateColors(color1, color2, (float)((yt + 40.0) / 80.0)).Value; pVertex += 4; pColor += 4; x = xt; y = yt; z = zt; } } } // notify series that data has changed as we've modified it directly using pointers surface.Data.SetCount(dataPointCount); } nChartControl1.Refresh(); }
protected void Page_Load(object sender, EventArgs e) { nChartControl1.BackgroundStyle.FrameStyle.Visible = false; nChartControl1.Settings.JitterMode = JitterMode.Enabled; // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Vertex Surface Fill Custom Colors "); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 14, FontStyle.Italic); title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur; // setup chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.BoundsMode = BoundsMode.Fit; chart.Width = 60.0f; chart.Depth = 60.0f; chart.Height = 40.0f; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); chart.Projection.Elevation = 45; chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft); // setup Y axis NLinearScaleConfigurator scaleY = new NLinearScaleConfigurator(); scaleY.RoundToTickMax = false; scaleY.RoundToTickMin = false; scaleY.MinTickDistance = new NLength(10, NGraphicsUnit.Point); scaleY.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Left, ChartWallType.Back }; scaleY.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = scaleY; // setup X axis NLinearScaleConfigurator scaleX = new NLinearScaleConfigurator(); scaleX.RoundToTickMax = false; scaleX.RoundToTickMin = false; scaleX.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Floor, ChartWallType.Back }; scaleX.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX; // setup Z axis NLinearScaleConfigurator scaleZ = new NLinearScaleConfigurator(); scaleZ.RoundToTickMax = false; scaleZ.RoundToTickMin = false; scaleZ.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Floor, ChartWallType.Left }; scaleZ.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot; chart.Axis(StandardAxis.Depth).ScaleConfigurator = scaleZ; // apply layout ApplyLayoutTemplate(0, nChartControl1, chart, title, null); // add data Random random = new Random(); // setup surface series NVertexSurfaceSeries surface = new NVertexSurfaceSeries(); chart.Series.Add(surface); surface.Name = "Surface"; surface.SyncPaletteWithAxisScale = false; surface.PaletteSteps = 8; surface.ValueFormatter.FormatSpecifier = "0.00"; surface.FillMode = SurfaceFillMode.CustomColors; surface.FrameMode = SurfaceFrameMode.None; surface.VertexPrimitive = VertexPrimitive.Triangles; surface.Data.UseColors = true; surface.UseIndices = true; int cubeSide = 8; int dataPointCount = 8 * (int)Math.Pow(cubeSide, 3); Random rand = new Random(); surface.Data.SetCapacity(dataPointCount); uint currentIndex = 0; uint[] cubeIndices = new uint[] { // bottom 0, 1, 3, 0, 3, 2, // left 2, 0, 4, 2, 4, 6, // right 1, 3, 5, 3, 7, 5, // front 0, 1, 4, 1, 5, 4, // back 2, 6, 3, 3, 6, 7, // top 4, 5, 6, 5, 7, 6 }; // generate all vertexes and colors for (int x = 0; x < cubeSide; x++) { double x1 = x + 0.1; double x2 = x + 1 - 0.1; int r1 = (byte)(x1 * 255.0 / cubeSide); int r2 = (byte)(x1 * 255.0 / cubeSide); for (int y = 0; y < cubeSide; y++) { double y1 = y + 0.1; double y2 = y + 1 - 0.1; int g1 = (byte)(y1 * 255.0 / cubeSide); int g2 = (byte)(y1 * 255.0 / cubeSide); for (int z = 0; z < cubeSide; z++) { double z1 = z + 0.1; double z2 = z + 1 - 0.1; int b1 = (byte)(z1 * 255.0 / cubeSide); int b2 = (byte)(z1 * 255.0 / cubeSide); surface.Data.AddValueColor(new NVector3DD(x1, y1, z1), Color.FromArgb(r1, g1, b1)); surface.Data.AddValueColor(new NVector3DD(x2, y1, z1), Color.FromArgb(r2, g1, b1)); surface.Data.AddValueColor(new NVector3DD(x1, y2, z1), Color.FromArgb(r1, g2, b1)); surface.Data.AddValueColor(new NVector3DD(x2, y2, z1), Color.FromArgb(r2, g2, b1)); surface.Data.AddValueColor(new NVector3DD(x1, y1, z2), Color.FromArgb(r1, g1, b2)); surface.Data.AddValueColor(new NVector3DD(x2, y1, z2), Color.FromArgb(r2, g1, b2)); surface.Data.AddValueColor(new NVector3DD(x1, y2, z2), Color.FromArgb(r1, g2, b2)); surface.Data.AddValueColor(new NVector3DD(x2, y2, z2), Color.FromArgb(r2, g2, b2)); // add indicess for (int i = 0; i < cubeIndices.Length; i++) { surface.Indices.Add(currentIndex + cubeIndices[i]); } currentIndex += 8; } } } }