private void UpdateTimeSpanScale(NTimeSpanScaleConfigurator timeSpanScale) { List <NTimeUnit> timeUnits = new List <NTimeUnit>(); if (MillisecondCheckBox.Checked) { timeUnits.Add(NTimeUnit.Millisecond); } if (SecondCheckBox.Checked) { timeUnits.Add(NTimeUnit.Second); } if (MinuteCheckBox.Checked) { timeUnits.Add(NTimeUnit.Minute); } if (HourCheckBox.Checked) { timeUnits.Add(NTimeUnit.Hour); } if (DayCheckBox.Checked) { timeUnits.Add(NTimeUnit.Day); } if (WeekCheckBox.Checked) { timeUnits.Add(NTimeUnit.Week); } timeSpanScale.EnableUnitSensitiveFormatting = EnableUnitSensitiveFormattingCheckBox.Checked; timeSpanScale.AutoDateTimeUnits = timeUnits.ToArray(); }
protected void Page_Load(object sender, EventArgs e) { nChartControl1.BackgroundStyle.FrameStyle.Visible = false; // set a chart title NLabel header = nChartControl1.Labels.AddHeader("Date Time Scale"); header.TextStyle.FontStyle = new NFontStyle("Times New Roman", 14, FontStyle.Italic); header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur; header.ContentAlignment = ContentAlignment.BottomRight; header.Location = new NPointL( new NLength(2, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); NChart chart = nChartControl1.Charts[0]; chart.BoundsMode = BoundsMode.Stretch; // add a strip line style NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator(); NScaleStripStyle stripStyle = new NScaleStripStyle(); stripStyle.FillStyle = new NColorFillStyle(Color.Beige); stripStyle.SetShowAtWall(ChartWallType.Back, true); stripStyle.SetShowAtWall(ChartWallType.Left, true); stripStyle.Interlaced = true; linearScale.StripStyles.Add(stripStyle); chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = linearScale; // create line serie and dispay them on vertical axis NLineSeries line = new NLineSeries(); chart.Series.Add(line); line.UseXValues = true; line.Name = "Line"; line.DataLabelStyle.Visible = false; line.InflateMargins = true; NTimeSpanScaleConfigurator timeSpanScale = new NTimeSpanScaleConfigurator(); timeSpanScale.LabelStyle.Angle = new NScaleLabelAngle(ScaleLabelAngleMode.View, 90); timeSpanScale.LabelStyle.ContentAlignment = ContentAlignment.MiddleLeft; chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = timeSpanScale; chart.BoundsMode = BoundsMode.Stretch; chart.Location = new NPointL( new NLength(5, NRelativeUnit.ParentPercentage), new NLength(15, NRelativeUnit.ParentPercentage)); chart.Size = new NSizeL( new NLength(85, NRelativeUnit.ParentPercentage), new NLength(80, NRelativeUnit.ParentPercentage)); // apply style sheet NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Fresh); styleSheet.Apply(nChartControl1.Document); if (!IsPostBack) { SampleTimeRangeDropDownList.Items.Add("Milliseconds"); SampleTimeRangeDropDownList.Items.Add("Seconds"); SampleTimeRangeDropDownList.Items.Add("Minutes"); SampleTimeRangeDropDownList.Items.Add("Hours"); SampleTimeRangeDropDownList.Items.Add("Days"); SampleTimeRangeDropDownList.Items.Add("Weeks"); SampleTimeRangeDropDownList.SelectedIndex = 2; // minutes EnableUnitSensitiveFormattingCheckBox.Checked = true; } UpdateTimeSpanScale(timeSpanScale); FillDummyData(line); }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Time Span Scale"); title.TextStyle.TextFormat = TextFormat.XML; title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic); title.ContentAlignment = ContentAlignment.BottomCenter; title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); // no legend nChartControl1.Legends.Clear(); // setup chart NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0]; chart.BoundsMode = BoundsMode.Stretch; // add a range selection, snapped to the vertical axis min/max values NRangeSelection rangeSelection = new NRangeSelection(); rangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper(); chart.RangeSelections.Add(rangeSelection); // add interlaced stripe to the Y axis NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator; 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); // Add a line series m_Line = new NLineSeries(); chart.Series.Add(m_Line); m_Line.UseXValues = true; m_Line.UseXValues = true; m_Line.DataLabelStyle.Visible = false; m_Line.SamplingMode = SeriesSamplingMode.Enabled; // create a date time scale m_TimeSpanScale = new NTimeSpanScaleConfigurator(); chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = m_TimeSpanScale; // apply style sheet NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.Fresh); styleSheet.Apply(nChartControl1.Document); NAxis xAxis = chart.Axis(StandardAxis.PrimaryX); xAxis.ScrollBar.Visible = true; // init form controls EnableUnitSensitiveFormattingCheckBox.Checked = true; MillisecondCheckBox.Checked = true; SecondCheckBox.Checked = true; MinuteCheckBox.Checked = true; HourCheckBox.Checked = true; DayCheckBox.Checked = true; WeekCheckBox.Checked = true; UpdateDateTimeScale(); StepUnitComboBox.Items.Add("Millisecond"); StepUnitComboBox.Items.Add("Second"); StepUnitComboBox.Items.Add("Minute"); StepUnitComboBox.Items.Add("Hour"); StepUnitComboBox.Items.Add("Day"); StepUnitComboBox.Items.Add("Week"); StepUnitComboBox.SelectedIndex = 2; timer1.Start(); nChartControl1.Refresh(); }