void OnGenerateRandomDataButtonClick(NEventArgs arg) { DateTime startDate = m_StartDateTimeBox.SelectedDate; DateTime endDate = m_EndDateTimeBox.SelectedDate; if (startDate > endDate) { DateTime temp = startDate; startDate = endDate; endDate = temp; } // Get the line series from the chart NLineSeries line = (NLineSeries)m_Chart.Series[0]; TimeSpan span = endDate - startDate; span = new TimeSpan(span.Ticks / 30); line.DataPoints.Clear(); if (span.Ticks > 0) { Random random = new Random(); while (startDate < endDate) { line.DataPoints.Add(new NLineDataPoint(NDateTimeHelpers.ToOADate(startDate), random.Next(100))); startDate += span; } } }
private void GenerateData() { double open, high, low, close; m_StockPrice.DataPoints.Clear(); m_StockVolume.DataPoints.Clear(); DateTime dt = DateTime.Now - new TimeSpan(120, 0, 0, 0); double dPrevClose = 100; double dVolume = 15; Random random = new Random(); for (int nIndex = 0; nIndex < 100; nIndex++) { open = dPrevClose; if (dPrevClose < 25 || random.NextDouble() > 0.5) { // upward price change close = open + (2 + (random.NextDouble() * 20)); high = close + (random.NextDouble() * 10); low = open - (random.NextDouble() * 10); } else { // downward price change close = open - (2 + (random.NextDouble() * 20)); high = open + (random.NextDouble() * 10); low = close - (random.NextDouble() * 10); } if (low < 1) { low = 1; } while (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday) { dt = dt.AddDays(1); } // add stock / volume data m_StockPrice.DataPoints.Add(new NStockDataPoint(NDateTimeHelpers.ToOADate(dt), open, close, high, low)); m_StockVolume.DataPoints.Add(new NAreaDataPoint(NDateTimeHelpers.ToOADate(dt), dVolume)); // move forward dVolume += 10 * (0.5 - random.NextDouble()); if (dVolume <= 0) { dVolume += 15; } dt = dt.AddDays(1); } }
/// <summary> /// /// </summary> /// <param name="threeLineBreak"></param> private void GenerateData(NThreeLineBreakSeries threeLineBreak) { NStockDataGenerator dataGenerator = new NStockDataGenerator(new NRange(50, 350), 0.002, 2); dataGenerator.Reset(); DateTime dt = DateTime.Now; for (int i = 0; i < 100; i++) { threeLineBreak.DataPoints.Add(new NThreeLineBreakDataPoint(NDateTimeHelpers.ToOADate(dt), dataGenerator.GetNextValue())); dt = dt.AddDays(1); } }
void GenerateData() { // generate data for 30 weeks DateTime dtNow = DateTime.Now; DateTime dtEnd = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0); DateTime dtStart = NDateTimeUnit.Week.Add(dtEnd, -30); NDateTimeSpan span = new NDateTimeSpan(1, NDateTimeUnit.Day); long count = span.GetSpanCountInRange(new NDateTimeRange(dtStart, dtEnd)); double open, high, low, close; m_Stock.DataPoints.Clear(); Random random = new Random(); double prevClose = 100; for (int nIndex = 0; nIndex < count; nIndex++) { open = prevClose; if (prevClose < 25 || random.NextDouble() > 0.5) { // upward price change close = open + (2 + (random.NextDouble() * 20)); high = close + (random.NextDouble() * 10); low = open - (random.NextDouble() * 10); } else { // downward price change close = open - (2 + (random.NextDouble() * 20)); high = open + (random.NextDouble() * 10); low = close - (random.NextDouble() * 10); } if (low < 1) { low = 1; } prevClose = close; m_Stock.DataPoints.Add(new NStockDataPoint(NDateTimeHelpers.ToOADate(dtNow), open, close, high, low)); dtNow = span.Add(dtNow); } }
private void GenerateData(DateTime dtStart, DateTime dtEnd, NDateTimeSpan span) { long count = span.GetSpanCountInRange(new NDateTimeRange(dtStart, dtEnd)); double open, high, low, close; m_Stock.DataPoints.Clear(); Random random = new Random(); DateTime dtNow = dtStart; double prevClose = 100; for (int nIndex = 0; nIndex < count; nIndex++) { open = prevClose; if (prevClose < 25 || random.NextDouble() > 0.5) { // upward price change close = open + (2 + (random.NextDouble() * 20)); high = close + (random.NextDouble() * 10); low = open - (random.NextDouble() * 10); } else { // downward price change close = open - (2 + (random.NextDouble() * 20)); high = open + (random.NextDouble() * 10); low = close - (random.NextDouble() * 10); } if (low < 1) { low = 1; } prevClose = close; m_Stock.DataPoints.Add(new NStockDataPoint(NDateTimeHelpers.ToOADate(dtNow), open, close, high, low)); dtNow = span.Add(dtNow); } }
/// <summary> /// /// </summary> /// <returns></returns> protected override NWidget CreateExampleContent() { NChartView chartView = CreateCartesianChartView(); // configure title chartView.Surface.Titles[0].Text = "Weekly Schedule Work Calendar"; // configure chart m_Chart = (NCartesianChart)chartView.Surface.Charts[0]; m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear); NRangeSeries ranges = new NRangeSeries(); m_Chart.Series.Add(ranges); ranges.DataLabelStyle = new NDataLabelStyle(false); ranges.UseXValues = true; DateTime dt = new DateTime(2014, 4, 14); Random rand = new Random(); NRangeTimelineScale rangeTimeline = new NRangeTimelineScale(); rangeTimeline.EnableCalendar = true; m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = rangeTimeline; NLinearScale yScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale; yScale.MajorGridLines.Visible = true; // add interlaced strip NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1); strip.Interlaced = true; yScale.Strips.Add(strip); yScale.Title.Text = "Weekly Workload in %"; NWorkCalendar workCalendar = rangeTimeline.Calendar; // show only the working days on the scale NWeekDayRule weekDayRule = new NWeekDayRule(ENWeekDayBit.Monday | ENWeekDayBit.Tuesday | ENWeekDayBit.Wednesday | ENWeekDayBit.Thursday | ENWeekDayBit.Friday); workCalendar.Rules.Add(weekDayRule); // generate data for week working days for (int i = 0; i < 21; i++) { if (dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday) { ranges.DataPoints.Add(new NRangeDataPoint(NDateTimeHelpers.ToOADate(dt), 0, NDateTimeHelpers.ToOADate(dt + new TimeSpan(1, 0, 0, 0)), rand.NextDouble() * 70 + 30.0d)); } dt += new TimeSpan(1, 0, 0, 0); } ConfigureInteractivity(m_Chart); chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, false)); return(chartView); }
/// <summary> /// /// </summary> /// <returns></returns> protected override NWidget CreateExampleContent() { NChartView chartView = CreateCartesianChartView(); // configure title chartView.Surface.Titles[0].Text = "Point And Figure"; // configure chart NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0]; chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear); // setup X axis NPriceTimeScale priceScale = new NPriceTimeScale(); priceScale.InnerMajorTicks.Stroke = new NStroke(0.0, NColor.Black); chart.Axes[ENCartesianAxis.PrimaryX].Scale = priceScale; const int nInitialBoxSize = 5; // setup Y axis NLinearScale scaleY = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale; scaleY.MajorTickMode = ENMajorTickMode.CustomStep; scaleY.CustomStep = nInitialBoxSize; scaleY.OuterMajorTicks.Width = 0; scaleY.InnerMajorTicks.Width = 0; scaleY.AutoMinorTicks = true; scaleY.MinorTickCount = 1; scaleY.InflateViewRangeBegin = false; scaleY.InflateViewRangeEnd = false; scaleY.MajorGridLines.Stroke = new NStroke(0, NColor.Black); scaleY.MinorGridLines.Stroke = new NStroke(1, NColor.Black); float[] highValues = new float[20] { 21.3F, 42.4F, 11.2F, 65.7F, 38.0F, 71.3F, 49.54F, 83.7F, 13.9F, 56.12F, 27.43F, 23.1F, 31.0F, 75.4F, 9.3F, 39.12F, 10.0F, 44.23F, 21.76F, 49.2F }; float[] lowValues = new float[20] { 12.1F, 14.32F, 8.43F, 36.0F, 13.5F, 47.34F, 24.54F, 68.11F, 6.87F, 23.3F, 12.12F, 14.54F, 25.0F, 37.2F, 3.9F, 23.11F, 1.9F, 14.0F, 8.23F, 34.21F }; // setup Point & Figure series m_PointAndFigure = new NPointAndFigureSeries(); m_PointAndFigure.UseXValues = true; chart.Series.Add(m_PointAndFigure); DateTime dt = DateTime.Now; // fill data int count = highValues.Length; for (int i = 0; i < count; i++) { m_PointAndFigure.DataPoints.Add(new NPointAndFigureDataPoint(NDateTimeHelpers.ToOADate(dt), highValues[i], lowValues[i])); dt = dt.AddDays(1); } chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, false)); return(chartView); }
/// <summary> /// /// </summary> /// <returns></returns> protected override NWidget CreateExampleContent() { NChartView chartView = CreateCartesianChartView(); // configure title chartView.Surface.Titles[0].Text = "Daily Schedule Work Calendar"; // configure chart m_Chart = (NCartesianChart)chartView.Surface.Charts[0]; m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear); NRangeSeries ranges = new NRangeSeries(); m_Chart.Series.Add(ranges); ranges.DataLabelStyle = new NDataLabelStyle(false); ranges.UseXValues = true; DateTime dt = new DateTime(2014, 4, 14); Random rand = new Random(); NRangeTimelineScale rangeTimeline = new NRangeTimelineScale(); rangeTimeline.EnableCalendar = true; rangeTimeline.InflateViewRangeEnd = false; rangeTimeline.InflateViewRangeBegin = false; m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = rangeTimeline; NLinearScale yScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale; yScale.MajorGridLines.Visible = true; // add interlaced strip NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1); strip.Interlaced = true; yScale.Strips.Add(strip); yScale.Title.Text = "Daily Workload in %"; NWorkCalendar workCalendar = rangeTimeline.Calendar; NDateTimeRangeRule dateTimeRangeRule = null; for (int i = 0; i < 120; i++) { int hourOfTheDay = i % 24; if (hourOfTheDay < 8 || hourOfTheDay > 18) { DateTime curDate = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0); if (dateTimeRangeRule != null) { if (dateTimeRangeRule.Range.Begin != curDate) { dateTimeRangeRule = null; } } if (dateTimeRangeRule == null) { dateTimeRangeRule = new NDateTimeRangeRule(new NDateTimeRange(curDate, curDate + new TimeSpan(24, 0, 0)), true); workCalendar.Rules.Add(dateTimeRangeRule); } dateTimeRangeRule.Schedule.SetHourRange(dt.Hour, dt.Hour + 1, true); } else { ranges.DataPoints.Add(new NRangeDataPoint(NDateTimeHelpers.ToOADate(dt), 0, NDateTimeHelpers.ToOADate(dt + new TimeSpan(1, 0, 0)), rand.NextDouble() * 70 + 30.0d)); } dt += new TimeSpan(1, 0, 0); } ConfigureInteractivity(m_Chart); chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, false)); return(chartView); }