private void GenerateData(NDataSeriesDouble dataSeries, int count) { for (int i = 0; i < count; i++) { dataSeries.Add(Random.NextDouble() * 59 + 1); } }
private void CalcFunction() { NDataSeriesDouble ds = m_FuncCalculator.Calculate(); if (ds == null) { return; } m_Chart.Axis(StandardAxis.PrimaryY).ConstLines.Clear(); m_Line.Visible = false; if (m_GroupingCombo.SelectedIndex == 0) { // add a constline if there is no grouping NAxisConstLine cl = m_Chart.Axis(StandardAxis.PrimaryY).ConstLines.Add(); cl.StrokeStyle.Width = new NLength(2, NGraphicsUnit.Pixel); cl.StrokeStyle.Color = Color.Red; cl.Value = (double)ds.GetValueForIndex(0); } else { m_Line.Visible = true; m_Line.Values = ds; m_Line.Values.ValueFormatter = new NNumericValueFormatter("0.00"); } nChartControl1.Refresh(); }
private void CalcFunction() { NDataSeriesDouble ds = m_FuncCalculator.Calculate(); if (ds == null) { return; } m_Chart.Axis(StandardAxis.PrimaryY).ConstLines.Clear(); m_Line.Visible = false; NAxis axis = m_Chart.Axis(StandardAxis.PrimaryY); axis.View = new NContentAxisView(); if (m_GroupingCombo.SelectedIndex == 0) { SetConstline(ds); } else { m_Line.Visible = true; m_Line.Values = ds; m_Line.Values.ValueFormatter = new NNumericValueFormatter("0.00"); } nChartControl1.Refresh(); }
private void SetConstline() { NAxis axis = m_Chart.Axis(StandardAxis.PrimaryY); // add a constline if necessary if (axis.ConstLines.Count == 0) { axis.ConstLines.Add(); } // the line series won't be used m_Line.Visible = false; // calc the sum of the elements NDataSeriesDouble ds = m_FuncCalculator.Calculate(); // add a new constline NAxisConstLine cl = (NAxisConstLine)axis.ConstLines[0]; cl.StrokeStyle.Width = new NLength(2, NGraphicsUnit.Pixel); cl.StrokeStyle.Color = Color.Red; cl.Value = (double)ds.GetValueForIndex(0); m_LabelSum.Text = cl.Value.ToString(); // set proper scale for the axis, so that it includes the constline if (cl.Value >= 0) { // if the sum is positive - compare it to the largest value m_FuncCalculator.Expression = "MAX(values)"; ds = m_FuncCalculator.Calculate(); double dMax = (double)ds.GetValueForIndex(0); if (cl.Value > dMax) { dMax = cl.Value; } axis.View = new NRangeAxisView(new NRange1DD(0, dMax), false, true); } else { // if the sum is negative - compare it to the smallest value m_FuncCalculator.Expression = "MIN(values)"; ds = m_FuncCalculator.Calculate(); double dMin = (double)ds.GetValueForIndex(0); if (cl.Value < dMin) { dMin = cl.Value; } axis.View = new NRangeAxisView(new NRange1DD(dMin, 0), true, false); } }
private void FillDataSeries(NDataSeriesDouble ds, int nCount) { ds.Clear(); for (int i = 0; i < nCount; i++) { ds.Add(Random.NextDouble() * 3); } }
private void CalculateFunction() { NAxisConstLine cl = (NAxisConstLine)m_Chart.Axis(StandardAxis.PrimaryY).ConstLines[0]; NDataSeriesDouble ds = m_FuncCalculator.Calculate(); cl.Value = (double)ds.GetValueForIndex(0); m_LabelResult.Text = cl.Value.ToString(); }
private void UpdateFunctionLine() { NDataSeriesDouble ds = m_FuncCalculator.Calculate(); if (ds == null) { m_Line.Values.Clear(); } else { m_Line.Values = ds; m_Line.Values.ValueFormatter = new NNumericValueFormatter("0.00"); } nChartControl1.Refresh(); }
private void ChangeDataButton_Click(object sender, System.EventArgs e) { // generate random values m_Pie.Values.FillRandomRange(Random, 10, 0, 100); // store the new values m_Values = (NDataSeriesDouble)m_Pie.Values.Clone(); // restore other data series m_Pie.Detachments = (NDataSeriesDouble)m_Detachments.Clone(); m_Pie.Labels = (NDataSeriesString)m_Labels.Clone(); m_Pie.FillStyles = (NIndexedAttributeSeries)m_FillStyles.Clone(); m_Pie.BorderStyles = (NIndexedAttributeSeries)m_BorderStyles.Clone(); m_bGroupedData = false; nChartControl1.Refresh(); }
private void GenerateData(NDataSeriesDouble ds1, NDataSeriesDouble ds2, int nTotalCount, int nMaxEmptyCount) { SortedList arrEmptyIndices = new SortedList(); for (int i = 0; i < nMaxEmptyCount; i++) { int nEmptyIndex = Random.Next(0, nTotalCount); arrEmptyIndices[nEmptyIndex] = null; } for (int k = 0; k < nTotalCount; k++) { if (arrEmptyIndices.ContainsKey(k)) { ds1.Add(DBNull.Value); } else { ds1.Add(Random.NextDouble() * 10); } ds2.Add(Random.NextDouble() * 10); } }
public override void Initialize() { base.Initialize(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Grouped Pie Chart"); 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)); // setup chart NChart m_Chart = new NPieChart(); m_Chart.Enable3D = true; nChartControl1.Charts.Clear(); nChartControl1.Charts.Add(m_Chart); m_Chart.DisplayOnLegend = nChartControl1.Legends[0]; m_Chart.Projection.SetPredefinedProjection(PredefinedProjection.OrthogonalElevated); m_Chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.VividCameraLight); m_Chart.Location = new NPointL(new NLength(20, NRelativeUnit.ParentPercentage), new NLength(20, NRelativeUnit.ParentPercentage)); m_Chart.Size = new NSizeL(new NLength(60, NRelativeUnit.ParentPercentage), new NLength(60, NRelativeUnit.ParentPercentage)); // setup pie series m_Pie = (NPieSeries)m_Chart.Series.Add(SeriesType.Pie); m_Pie.Legend.Mode = SeriesLegendMode.DataPoints; m_Pie.Legend.Format = "<label> <percent>"; m_Pie.Legend.TextStyle.FontStyle.EmSize = new NLength(10, NGraphicsUnit.Pixel); m_Pie.ConnectorLength = new NLength(10); m_Pie.Labels.Add("Cars"); m_Pie.Labels.Add("Trains"); m_Pie.Labels.Add("Airplanes"); m_Pie.Labels.Add("Buses"); m_Pie.Labels.Add("Bikes"); m_Pie.Labels.Add("Motorcycles"); m_Pie.Labels.Add("Shuttles"); m_Pie.Labels.Add("Rollers"); m_Pie.Labels.Add("Ski"); m_Pie.Labels.Add("Surf"); // fill with random data m_Pie.Detachments.FillRandomRange(Random, 10, 0, 0); m_Pie.Values.FillRandomRange(Random, 10, 0, 100); // apply style sheet NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.FreshMultiColor); styleSheet.Apply(nChartControl1.Document); // store the original data and styles m_Values = (NDataSeriesDouble)m_Pie.Values.Clone(); m_Detachments = (NDataSeriesDouble)m_Pie.Detachments.Clone(); m_Labels = (NDataSeriesString)m_Pie.Labels.Clone(); m_FillStyles = (NIndexedAttributeSeries)m_Pie.FillStyles.Clone(); m_BorderStyles = (NIndexedAttributeSeries)m_Pie.BorderStyles.Clone(); m_bGroupedData = false; // init form controls GroupValueText.Text = "34"; m_sGroupLabel = "Other"; m_GroupColor = Color.Red; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // form controls ExpressionDropDownList.Items.Add("ADD(Green; Blue)"); ExpressionDropDownList.Items.Add("SUB(Green; Blue)"); ExpressionDropDownList.Items.Add("MUL(Green; Blue)"); ExpressionDropDownList.Items.Add("DIV(Green; Blue)"); ExpressionDropDownList.Items.Add("HIGH(Green; Blue)"); ExpressionDropDownList.Items.Add("LOW(Green; Blue)"); ExpressionDropDownList.SelectedIndex = 0; } nChartControl1.BackgroundStyle.FrameStyle.Visible = false; // add header NLabel header = nChartControl1.Labels.AddHeader("Basic functions"); 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)); // setup legend NLegend legend = nChartControl1.Legends[0]; legend.Location = new NPointL(legend.Location.X, new NLength(15, NRelativeUnit.ParentPercentage)); legend.Data.MarkSize = new NSizeL(5, 5); // setup chart NChart chart = nChartControl1.Charts[0]; chart.Enable3D = true; chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal); chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.MetallicLustre); chart.BoundsMode = BoundsMode.Stretch; chart.Location = new NPointL( new NLength(8, NRelativeUnit.ParentPercentage), new NLength(17, NRelativeUnit.ParentPercentage)); chart.Size = new NSizeL( new NLength(75, NRelativeUnit.ParentPercentage), new NLength(75, NRelativeUnit.ParentPercentage)); chart.Wall(ChartWallType.Left).Visible = false; chart.Wall(ChartWallType.Floor).Visible = false; chart.Axis(StandardAxis.Depth).Visible = false; // add a line series for the function NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line); line.Name = "Function"; line.DataLabelStyle.Format = "<value>"; line.MarkerStyle.PointShape = PointShape.Sphere; line.MarkerStyle.Visible = true; line.MarkerStyle.BorderStyle.Width = new NLength(0, NGraphicsUnit.Pixel); line.MarkerStyle.FillStyle = new NColorFillStyle(Color.Crimson); line.Legend.Mode = SeriesLegendMode.None; line.Values.ValueFormatter = new NNumericValueFormatter("0.00"); line.Legend.TextStyle = new NTextStyle(new NFontStyle("Arial", 7)); // add the first bar NBarSeries bar1 = (NBarSeries)chart.Series.Add(SeriesType.Bar); bar1.Name = "Bar1"; bar1.Values.Name = "Green"; bar1.Values.ValueFormatter = new NNumericValueFormatter("0.00"); bar1.MultiBarMode = MultiBarMode.Series; bar1.DataLabelStyle.Visible = false; bar1.Legend.Mode = SeriesLegendMode.DataPoints; bar1.FillStyle = new NColorFillStyle(Color.SeaGreen); bar1.BorderStyle.Width = new NLength(0, NGraphicsUnit.Pixel); bar1.BarShape = BarShape.CutEdgeBar; bar1.Legend.TextStyle = new NTextStyle(new NFontStyle("Arial", 7)); // add the second bar NBarSeries bar2 = (NBarSeries)chart.Series.Add(SeriesType.Bar); bar2.Name = "Bar2"; bar2.Values.Name = "Blue"; bar2.Values.ValueFormatter = new NNumericValueFormatter("0.00"); bar2.MultiBarMode = MultiBarMode.Clustered; bar2.DataLabelStyle.Visible = false; bar2.Legend.Mode = SeriesLegendMode.DataPoints; bar2.FillStyle = new NColorFillStyle(Color.CornflowerBlue); bar2.BorderStyle.Width = new NLength(0, NGraphicsUnit.Pixel); bar2.BarShape = BarShape.CutEdgeBar; bar2.Legend.TextStyle = new NTextStyle(new NFontStyle("Arial", 7)); // fill with random data FillDataSeries(bar1.Values, 5); FillDataSeries(bar2.Values, 5); funcCalculator = new NFunctionCalculator(); funcCalculator.Arguments.Clear(); funcCalculator.Arguments.Add(bar1.Values); funcCalculator.Arguments.Add(bar2.Values); funcCalculator.Expression = ExpressionDropDownList.SelectedItem.Text; NDataSeriesDouble ds = funcCalculator.Calculate(); if (ds == null) { line.Values.Clear(); } else { line.Values = ds; line.Values.ValueFormatter = new NNumericValueFormatter("0.00"); } }
private void SetConstline(NDataSeriesDouble ds) { NAxis axis = m_Chart.Axis(StandardAxis.PrimaryY); // add a constline if necessary if (axis.ConstLines.Count == 0) { axis.ConstLines.Add(); } // the line series won't be used m_Line.Visible = false; // add a new constline NAxisConstLine cl = (NAxisConstLine)axis.ConstLines[0]; cl.StrokeStyle.Width = new NLength(3, NGraphicsUnit.Pixel); cl.StrokeStyle.Color = Color.Green; cl.Value = (double)ds.GetValueForIndex(0); string text = cl.Value.ToString(); if (text.Length > 7) { text = text.Substring(0, 7); } /* NAxisCustomLabel axisLabel = axis.CustomLabels.Add(); * axisLabel.Offset = 3; * axisLabel.TextStyle.BackplaneStyle.Visible = true; * axisLabel.Angle = 180; * axisLabel.Text = text; * axisLabel.Value = cl.Value;*/ // set proper scale for the axis, so that it includes the constline NDataSeriesSubset subset = new NDataSeriesSubset(); subset.AddRange(0, ds.Count - 1); double max1 = m_Line1.Values.Evaluate("MAX", subset); double min1 = m_Line1.Values.Evaluate("MIN", subset); double max2 = m_Line2.Values.Evaluate("MAX", subset); double min2 = m_Line2.Values.Evaluate("MIN", subset); if (max1 < max2) { max1 = max2; } if (min1 > min2) { min1 = min2; } if (cl.Value > max1) { axis.View = new NRangeAxisView(new NRange1DD(double.MinValue, cl.Value), false, true); } else if (cl.Value < min1) { axis.View = new NRangeAxisView(new NRange1DD(cl.Value, double.MaxValue), true, false); } }