private void UpdateRegions() { m_Bar1.Values.Clear(); m_Bar2.Values.Clear(); // add custom labels to the X axis NChart chart = nChartControl1.Charts[0]; NOrdinalScaleConfigurator ordinalScale = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NOrdinalScaleConfigurator; ordinalScale.Labels.Clear(); ordinalScale.CustomLabels.Clear(); if (ShowNorthAmericaCheckBox.Checked) { ordinalScale.Labels.Add("USA"); ordinalScale.Labels.Add("Canada"); ordinalScale.Labels.Add("Mexico"); NCustomRangeLabel rangeLabel = new NCustomRangeLabel(); rangeLabel.Text = "Sales for North America"; rangeLabel.Range = new NRange1DD(0, 2); ordinalScale.CustomLabels.Add(rangeLabel); m_Bar1.Values.Add(Random.Next(10, 300)); m_Bar1.Values.Add(Random.Next(10, 300)); m_Bar1.Values.Add(Random.Next(10, 300)); m_Bar2.Values.Add(Random.Next(10, 300)); m_Bar2.Values.Add(Random.Next(10, 300)); m_Bar2.Values.Add(Random.Next(10, 300)); } if (ShowEuropeCheckBox.Checked) { ordinalScale.Labels.Add("Germany"); ordinalScale.Labels.Add("UK"); ordinalScale.Labels.Add("France"); NCustomRangeLabel rangeLabel = new NCustomRangeLabel(); rangeLabel.Text = "Sales for Europe"; rangeLabel.Range = new NRange1DD(m_Bar1.Values.Count, m_Bar1.Values.Count + 2); ordinalScale.CustomLabels.Add(rangeLabel); m_Bar1.Values.Add(Random.Next(10, 300)); m_Bar1.Values.Add(Random.Next(10, 300)); m_Bar1.Values.Add(Random.Next(10, 300)); m_Bar2.Values.Add(Random.Next(10, 300)); m_Bar2.Values.Add(Random.Next(10, 300)); m_Bar2.Values.Add(Random.Next(10, 300)); } }
private void UpdateLabels() { // add custom labels to the Y axis NChart chart = nChartControl1.Charts[0]; NOrdinalScaleConfigurator scale = chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NOrdinalScaleConfigurator; for (int i = 0; i < scale.CustomLabels.Count; i++) { NCustomRangeLabel rangeLabel = (NCustomRangeLabel)scale.CustomLabels[i]; rangeLabel.Style.TickMode = (RangeLabelTickMode)LabelTickModeComboBox.SelectedIndex; rangeLabel.Style.VisibilityMode = (ScaleLabelVisibilityMode)LabelVisibilityModeComboBox.SelectedIndex; rangeLabel.Style.FitMode = FitModeFromIndex(LabelFitModeComboBox.SelectedIndex); rangeLabel.Style.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, (float)LabelAngleNumericUpDown.Value); rangeLabel.Style.TickPadding = new NLength((float)TickPaddingNumericUpDown.Value, NGraphicsUnit.Point); rangeLabel.Style.TickOffset = new NLength((float)TickOffsetNumericUpDown.Value, NGraphicsUnit.Point); rangeLabel.Style.Offset = new NLength((float)TextOffsetNumericUpDown.Value, NGraphicsUnit.Point); rangeLabel.Style.TextPadding = new NLength((float)TextPaddingNumericUpDown.Value, NGraphicsUnit.Point); } nChartControl1.Refresh(); }
private void ApplyScaleSectionToAxis(NLinearScaleConfigurator scale, string text, NRange1DD range, Color color) { NScaleSectionStyle scaleSection = new NScaleSectionStyle(); scaleSection.Range = range; scaleSection.LabelTextStyle = new NTextStyle(); scaleSection.LabelTextStyle.FillStyle = new NColorFillStyle(color); scaleSection.LabelTextStyle.FontStyle = new NFontStyle("Arial", 10, FontStyle.Bold | FontStyle.Italic); scaleSection.MajorTickStrokeStyle = new NStrokeStyle(color); scale.Sections.Add(scaleSection); NCustomRangeLabel rangeLabel = new NCustomRangeLabel(range, text); rangeLabel.Style.WrapText = false; rangeLabel.Style.KeepInsideRuler = false; rangeLabel.Style.StrokeStyle.Color = color; rangeLabel.Style.TextStyle.FillStyle = new NColorFillStyle(Color.White); rangeLabel.Style.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 0); rangeLabel.Style.TickMode = RangeLabelTickMode.Center; scale.CustomLabels.Add(rangeLabel); }
private void ApplyScaleSectionToAxis(NLinearScale scale, string text, NRange range, NColor color) { NScaleSection scaleSection = new NScaleSection(); scaleSection.Range = range; scaleSection.LabelTextStyle = new NTextStyle(); scaleSection.LabelTextStyle.Fill = new NColorFill(color); scaleSection.LabelTextStyle.Font = new NFont("Arimo", 10, ENFontStyle.Bold | ENFontStyle.Italic); scaleSection.MajorTickStroke = new NStroke(color); scale.Sections.Add(scaleSection); NCustomRangeLabel rangeLabel = new NCustomRangeLabel(range, text); rangeLabel.LabelStyle.AlwaysInsideScale = false; rangeLabel.LabelStyle.VisibilityMode = ENScaleLabelVisibilityMode.TextInRuler; rangeLabel.LabelStyle.Stroke.Color = color; rangeLabel.LabelStyle.TextStyle.Fill = new NColorFill(NColor.White); rangeLabel.LabelStyle.Angle = new NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0); rangeLabel.LabelStyle.TickMode = ENRangeLabelTickMode.Center; scale.CustomLabels.Add(rangeLabel); }
public override void Initialize() { base.Initialize(); nChartControl1.Panels.Clear(); // set a chart title NLabel header = new NLabel("Company Sales by Region<br/><font size = '9pt'>Demonstrates how to use custom range labels to denote ranges on a scale</font>"); header.DockMode = PanelDockMode.Top; header.Margins = new NMarginsL(0, 10, 0, 10); header.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); header.TextStyle.TextFormat = TextFormat.XML; header.ContentAlignment = ContentAlignment.BottomRight; header.Location = new NPointL(new NLength(2, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); nChartControl1.Panels.Add(header); NLegend legend = new NLegend(); legend.Margins = new NMarginsL(10, 0, 10, 0); legend.DockMode = PanelDockMode.Right; legend.FitAlignment = ContentAlignment.TopCenter; nChartControl1.Panels.Add(legend); NCartesianChart chart = new NCartesianChart(); nChartControl1.Panels.Add(chart); chart.DisplayOnLegend = legend; chart.DockMode = PanelDockMode.Fill; chart.BoundsMode = BoundsMode.Stretch; chart.Margins = new NMarginsL(10, 0, 0, 10); chart.Axis(StandardAxis.Depth).Visible = false; // add range selection NRangeSelection rangeSelection = new NRangeSelection(); rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper(); chart.RangeSelections.Add(rangeSelection); // add the first bar m_Bar1 = (NBarSeries)chart.Series.Add(SeriesType.Bar); m_Bar1.Name = "Coca Cola"; m_Bar1.MultiBarMode = MultiBarMode.Series; m_Bar1.DataLabelStyle.Format = "<value>"; // add the second bar m_Bar2 = (NBarSeries)chart.Series.Add(SeriesType.Bar); m_Bar2.Name = "Pepsi"; m_Bar2.MultiBarMode = MultiBarMode.Clustered; m_Bar2.DataLabelStyle.Format = "<value>"; // apply style sheet NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Fresh); styleSheet.Apply(nChartControl1.Document); // add custom labels to the X axis NAxis xAxis = chart.Axis(StandardAxis.PrimaryX); xAxis.ScrollBar.Visible = true; NOrdinalScaleConfigurator ordinalScale = xAxis.ScaleConfigurator as NOrdinalScaleConfigurator; ordinalScale.AutoLabels = false; ordinalScale.OuterMajorTickStyle.Visible = false; ordinalScale.InnerMajorTickStyle.Visible = false; // add custom labels to the Y axis chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(0, 320)); NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; linearScale.RoundToTickMax = false; NCustomRangeLabel rangeLabel = new NCustomRangeLabel(new NRange1DD(240, 320), "Target Volume"); rangeLabel.Style.TickMode = RangeLabelTickMode.Center; rangeLabel.Style.WrapText = true; rangeLabel.Style.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 0); linearScale.CustomLabels.Add(rangeLabel); // add interlace stripe NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1); stripStyle.Interlaced = true; stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.StripStyles.Add(stripStyle); // configure interactivity nChartControl1.Controller.Tools.Add(new NPanelSelectorTool()); nChartControl1.Controller.Tools.Add(new NAxisScrollTool()); nChartControl1.Controller.Tools.Add(new NDataZoomTool()); // init form controls LabelTickModeComboBox.FillFromEnum(typeof(RangeLabelTickMode)); LabelVisibilityModeComboBox.FillFromEnum(typeof(ScaleLabelVisibilityMode)); LabelFitModeComboBox.FillFromEnum(typeof(RangeLabelFitMode)); NRangeScaleLabelStyle defaultStyle = new NRangeScaleLabelStyle(); LabelTickModeComboBox.SelectedIndex = (int)defaultStyle.TickMode; LabelVisibilityModeComboBox.SelectedIndex = (int)defaultStyle.VisibilityMode; LabelFitModeComboBox.SelectedIndex = (int)defaultStyle.FitMode; LabelAngleNumericUpDown.Value = (decimal)defaultStyle.Angle.CustomAngle; TickPaddingNumericUpDown.Value = (decimal)defaultStyle.TickPadding.Value; TickOffsetNumericUpDown.Value = (decimal)defaultStyle.TickOffset.Value; TextOffsetNumericUpDown.Value = (decimal)defaultStyle.Offset.Value; TextPaddingNumericUpDown.Value = (decimal)defaultStyle.TextPadding.Value; // add some data NorthAmericaCheckBox.Checked = true; EuropeCheckBox.Checked = true; AsiaCheckBox.Checked = true; SouthAmericaCheckBox.Checked = true; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShowNorthAmericaCheckBox.Checked = true; ShowEuropeCheckBox.Checked = true; } nChartControl1.BackgroundStyle.FrameStyle.Visible = false; nChartControl1.Panels.Clear(); // set a chart title NLabel header = new NLabel("Company Sales by Region<br/><font size = '9pt'>Demonstrates how to use custom range labels to denote ranges on a scale</font>"); header.TextStyle.FontStyle = new NFontStyle("Times New Roman", 14, FontStyle.Italic); header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur; header.TextStyle.TextFormat = TextFormat.XML; header.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Left; header.DockMode = PanelDockMode.Top; header.FitAlignment = ContentAlignment.MiddleLeft; header.Margins = new NMarginsL(5, 0, 10, 10); header.Location = new NPointL(new NLength(3, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); nChartControl1.Panels.Add(header); NCartesianChart chart = new NCartesianChart(); nChartControl1.Panels.Add(chart); // configure the legend and add it as child panel of the chart NLegend legend = new NLegend(); legend.Margins = new NMarginsL(10, 0, 10, 0); legend.DockMode = PanelDockMode.Right; legend.FitAlignment = ContentAlignment.TopCenter; legend.Data.ExpandMode = LegendExpandMode.ColsOnly; legend.FillStyle = new NColorFillStyle(Color.FromArgb(125, Color.White)); legend.HorizontalBorderStyle.Width = new NLength(0); legend.VerticalBorderStyle.Width = new NLength(0); legend.OuterTopBorderStyle.Width = new NLength(0); legend.OuterLeftBorderStyle.Width = new NLength(0); legend.OuterBottomBorderStyle.Width = new NLength(0); legend.OuterRightBorderStyle.Width = new NLength(0); chart.ChildPanels.Add(legend); chart.DisplayOnLegend = legend; chart.DockMode = PanelDockMode.Fill; chart.BoundsMode = BoundsMode.Stretch; chart.Margins = new NMarginsL(2, 0, 2, 2); chart.Axis(StandardAxis.Depth).Visible = false; // add range selection NRangeSelection rangeSelection = new NRangeSelection(); rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper(); chart.RangeSelections.Add(rangeSelection); // add the first bar m_Bar1 = (NBarSeries)chart.Series.Add(SeriesType.Bar); m_Bar1.Name = "Coca Cola"; m_Bar1.MultiBarMode = MultiBarMode.Series; m_Bar1.DataLabelStyle.Format = "<value>"; // add the second bar m_Bar2 = (NBarSeries)chart.Series.Add(SeriesType.Bar); m_Bar2.Name = "Pepsi"; m_Bar2.MultiBarMode = MultiBarMode.Clustered; m_Bar2.DataLabelStyle.Format = "<value>"; // apply style sheet NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Fresh); styleSheet.Apply(nChartControl1.Document); // add custom labels to the X axis NAxis xAxis = chart.Axis(StandardAxis.PrimaryX); xAxis.ScrollBar.Visible = true; NOrdinalScaleConfigurator ordinalScale = xAxis.ScaleConfigurator as NOrdinalScaleConfigurator; ordinalScale.AutoLabels = false; ordinalScale.OuterMajorTickStyle.Visible = false; ordinalScale.InnerMajorTickStyle.Visible = false; // add custom labels to the Y axis chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(0, 320)); NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; linearScale.RoundToTickMax = false; NCustomRangeLabel rangeLabel = new NCustomRangeLabel(new NRange1DD(240, 320), "Target Volume"); rangeLabel.Style.TickMode = RangeLabelTickMode.Center; rangeLabel.Style.WrapText = true; rangeLabel.Style.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.Scale, 0); linearScale.CustomLabels.Add(rangeLabel); // add interlace stripe NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1); stripStyle.Interlaced = true; stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); linearScale.StripStyles.Add(stripStyle); UpdateRegions(); }