public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Temperature Measurements <br/><font size = '12pt'>Demonstrates how to Custom Program the Scale</font>"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.TextStyle.TextFormat = TextFormat.XML; title.SendToBack(); title.DockMode = PanelDockMode.Top; NLegend legend = nChartControl1.Legends[0]; legend.Mode = LegendMode.Disabled; NChart chart = (NCartesianChart)nChartControl1.Charts[0]; chart.BoundsMode = BoundsMode.Stretch; chart.DockMode = PanelDockMode.Fill; chart.DockMargins = new NMarginsL(2, 2, 10, 10); // create a point series NPointSeries point = (NPointSeries)chart.Series.Add(SeriesType.Point); point.Name = "Point Series"; point.DataLabelStyle.Visible = false; point.MarkerStyle.Visible = false; point.Size = new NLength(5, NGraphicsUnit.Point); Random rand = new Random(); for (int i = 0; i < 30; i++) { point.Values.Add(5 + rand.Next(90)); } NAxis primaryY = chart.Axis(StandardAxis.PrimaryY); primaryY.View = new NRangeAxisView(new NRange1DD(0, 100), true, true); NLinearScaleConfigurator linearScale = primaryY.ScaleConfigurator as NLinearScaleConfigurator; linearScale.RoundToTickMax = false; linearScale.RoundToTickMin = false; UpdateScale(); nChartControl1.Refresh(); }
public override void Initialize() { base.Initialize(); // configure the trackball NTrackballTool trackballTool = new NTrackballTool(); trackballTool.ProjectionChanged += new EventHandler(OnProjectionChanged); nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(trackballTool); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Axis Labels Orientation"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.DockMode = PanelDockMode.Top; title.Margins = new NMarginsL(10, 10, 10, 10); title.ContentAlignment = ContentAlignment.BottomCenter; title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); title.SendToBack(); // no legend nChartControl1.Legends.Clear(); // setup the chart m_Chart = (NCartesianChart)nChartControl1.Charts[0]; m_Chart.Enable3D = true; m_Chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveTilted); m_Chart.Depth = 50; m_Chart.Width = 50; m_Chart.Height = 50; m_Chart.BorderStyle = new NStrokeBorderStyle(BorderShape.RoundedRect); m_Chart.BoundsMode = BoundsMode.Fit; m_Chart.DockMode = PanelDockMode.Fill; m_Chart.Margins = new NMarginsL(30, 0, 30, 30); m_Chart.Padding = new NMarginsL(5, 5, 5, 5); m_Chart.BackgroundFillStyle = new NGradientFillStyle(Color.White, Color.LightGray); // setup Y axis NLinearScaleConfigurator scaleY = new NLinearScaleConfigurator(); scaleY.Title.Text = "Values"; // add interlaced stripe NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1); stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back, ChartWallType.Left }; stripStyle.Interlaced = true; scaleY.StripStyles.Add(stripStyle); m_Chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = scaleY; // configure the x axis labels (categories) NOrdinalScaleConfigurator scaleX = (NOrdinalScaleConfigurator)m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator; scaleX.AutoLabels = false; scaleX.Title.Text = "Categories Title"; scaleX.MajorTickMode = MajorTickMode.CustomStep; scaleX.LabelFitModes = new LabelFitMode[] { LabelFitMode.Stagger2, LabelFitMode.AutoScale }; for (int j = 0; j < categoriesCount; j++) { scaleX.Labels.Add("Category " + j.ToString()); } // configure the depth axis labels (series) NOrdinalScaleConfigurator scaleZ = m_Chart.Axis(StandardAxis.Depth).ScaleConfigurator as NOrdinalScaleConfigurator; scaleZ.AutoLabels = false; scaleZ.Title.Text = "Series Title"; scaleZ.MajorTickMode = MajorTickMode.CustomStep; scaleZ.Labels.Add("Series 1"); scaleZ.Labels.Add("Series 2"); scaleZ.Labels.Add("Series 3"); scaleZ.MajorGridStyle.SetShowAtWall(ChartWallType.Floor, true); scaleZ.LabelFitModes = new LabelFitMode[] { LabelFitMode.Stagger2, LabelFitMode.AutoScale }; // add series for (int i = 0; i < 3; i++) { NBarSeries bar = (NBarSeries)m_Chart.Series.Add(SeriesType.Bar); bar.InflateMargins = true; bar.BarShape = BarShape.SmoothEdgeBar; bar.DataLabelStyle.Visible = false; bar.Name = "Series " + i.ToString(); bar.Values.FillRandomRange(Random, categoriesCount, 10, 30); } // apply style sheet NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.FreshMultiColor); styleSheet.Apply(nChartControl1.Document); // initialize controls on the form AngleModeComboBox.FillFromEnum(typeof(ScaleLabelAngleMode)); AngleModeComboBox.SelectedIndex = (int)ScaleLabelAngleMode.Scale; Use3DCheckBox.Checked = true; OnProjectionChanged(null, null); }
public override void Initialize() { base.Initialize(); nChartControl1.Panels.Clear(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Custom Scale Decorations"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.SendToBack(); title.Margins = new NMarginsL(20, 10, 20, 20); title.DockMode = PanelDockMode.Top; NCartesianChart chart = new NCartesianChart(); nChartControl1.Panels.Add(chart); chart.BoundsMode = BoundsMode.Stretch; chart.DockMode = PanelDockMode.Fill; chart.Margins = new NMarginsL(20, 2, 20, 20); chart.BackgroundFillStyle = new NColorFillStyle(Color.FromArgb(231, 231, 233)); chart.MaxDockZoneMargins = new NMarginsL(100000, 100000, 100000, 100000); NStrokeBorderStyle strokeBorder = new NStrokeBorderStyle(); strokeBorder.StrokeStyle.Color = Color.FromArgb(192, 192, 192); chart.BorderStyle = strokeBorder; int dpCount = 8; double[] bar1Values = new double[dpCount]; double[] bar2Values = new double[dpCount]; NLabelInfo[] xLabels = new NLabelInfo[dpCount]; // add some dummy data Random rand = new Random(); for (int i = 0; i < dpCount; i++) { bar1Values[i] = rand.Next(100); bar2Values[i] = rand.Next(100); xLabels[i] = new NLabelInfo(i, "Label" + i.ToString(), Color.FromArgb(100, 100, 100), i % 2 == 0 ? Color.Red : Color.Orange); } NLabelInfo[] yLabels = new NLabelInfo[9]; for (int i = 0; i < 9; i++) { yLabels[i].Text = ((i + 1) * 10).ToString() + "%"; yLabels[i].Value = (i + 1) * 10; yLabels[i].ForeColor = Color.FromArgb(100, 100, 100); yLabels[i].BackColor = Color.Transparent; } // add two bars series in cluster mode NBarSeries bar1 = new NBarSeries(); bar1.Values.AddRange(bar1Values); bar1.DataLabelStyle.Visible = false; bar1.MultiBarMode = MultiBarMode.Clustered; bar1.FillStyle = new NColorFillStyle(Color.FromArgb(21, 153, 215)); bar1.FillStyle.ImageFiltersStyle.Filters.Add(new NBevelAndEmbossImageFilter()); bar1.WidthPercent = 50; bar1.GapPercent = 20; chart.Series.Add(bar1); NBarSeries bar2 = new NBarSeries(); bar2.Values.AddRange(bar2Values); bar2.DataLabelStyle.Visible = false; bar2.MultiBarMode = MultiBarMode.Clustered; bar2.FillStyle = new NColorFillStyle(Color.FromArgb(113, 127, 138)); bar2.FillStyle.ImageFiltersStyle.Filters.Add(new NBevelAndEmbossImageFilter()); bar2.WidthPercent = 50; bar2.GapPercent = 20; chart.Series.Add(bar2); // add custom labels to the x axis NLinearScaleConfigurator xScale = new NLinearScaleConfigurator(); chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = xScale; chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD(-0.5, xLabels.Length - 0.5), true, true); xScale.LabelStyle.TextStyle.FillStyle = new NColorFillStyle(Color.FromArgb(100, 100, 100)); xScale.AutoLabels = false; xScale.OuterMajorTickStyle.Visible = false; xScale.InnerMajorTickStyle.Visible = false; xScale.LabelStyle.Offset = new NLength(10); xScale.RulerStyle.BorderStyle.Width = new NLength(0); xScale.RulerStyle.Height = new NLength(0); NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.FromArgb(240, 240, 240)), null, true, 0, 0, 1, 1); stripStyle.Interlaced = true; stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); xScale.StripStyles.Add(stripStyle); // hide the back wall chart.Wall(ChartWallType.Back).Visible = false; // configure the Y axis chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(0, 100), true, true); NLinearScaleConfigurator yScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; yScale.AutoLabels = false; yScale.MajorTickMode = MajorTickMode.CustomTicks; yScale.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true); yScale.MajorGridStyle.LineStyle.Color = Color.FromArgb(192, 192, 192); yScale.OuterMajorTickStyle.Visible = false; yScale.InnerMajorTickStyle.Visible = false; yScale.RulerStyle.BorderStyle.Width = new NLength(0); yScale.RulerStyle.Height = new NLength(0); yScale.CreateNewLevelForCustomLabels = true; // add labels NAxis xAxis = chart.Axis(StandardAxis.PrimaryX); NAxis yAxis = chart.Axis(StandardAxis.PrimaryY); AddLabels(xAxis, true, xLabels); AddLabels(yAxis, true, yLabels); // create cross NCustomWallDecorator xDecorator = new NCustomWallDecorator(); xDecorator.WallDecorations.Add(new NGridLine(-0.5, new NStrokeStyle(Color.FromArgb(190, 190, 190)), new ChartWallType[] { ChartWallType.Back }, true)); xAxis.Scale.WallDecorators.Add(xDecorator); NCustomWallDecorator yDecorator = new NCustomWallDecorator(); yDecorator.WallDecorations.Add(new NGridLine(0, new NStrokeStyle(Color.FromArgb(190, 190, 190)), new ChartWallType[] { ChartWallType.Back }, true)); yAxis.Scale.WallDecorators.Add(yDecorator); }