public void CreatePlot(InteractivePlotSurface2D plotSurface) { double[] data = new double[] { 0, 4, 3, 2, 5, 4, 2, 3 }; double[] data2 = new double[] { 5, 2, 4, 1, 2, 1, 5, 3 }; HistogramPlot hp = new HistogramPlot(); hp.OrdinateData = data; hp.RectangleBrush = RectangleBrushes.Horizontal.FaintRedFade; hp.Filled = true; hp.BaseOffset = -0.15; hp.BaseWidth = 0.25f; HistogramPlot hp2 = new HistogramPlot(); hp2.OrdinateData = data2; hp2.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade; hp2.Filled = true; hp2.BaseOffset = 0.15; hp2.BaseWidth = 0.25f; plotSurface.Clear(); plotSurface.Add(hp); plotSurface.Add(hp2); plotSurface.PlotBackBrush = RectangleBrushes.Vertical.FaintBlueFade; plotSurface.Refresh(); }
void ShowSampleInfo() { int index = lvSample.SelectedIndices[0]; try { wbSample.DocumentText = arrTranSmp[index].GetReport(); } catch { wbSample.DocumentText = ""; } psHist.Clear(); HistogramPlot hp = new HistogramPlot(); arrSmp[index].DoHistogram(useSturgess); hp.AbscissaData = arrTranSmp[index].CloneHistX(); hp.OrdinateData = arrTranSmp[index].CloneHistY(); hp.Pen = Pens.DarkBlue; hp.Filled = true; hp.RectangleBrush = new RectangleBrushes.HorizontalCenterFade(Color.Lavender, Color.Aqua); psHist.Add(hp); psHist.XAxis1.Label = "Значения признака"; psHist.YAxis1.Label = "Частота"; //psHist.Title = string.Format("Признак {0}, преобразование: {2}", // arrTranSmp[index].GetName(), arrTranSmp[index].GetMark(), // ((TranSample)arrTranSmp[index]).GetTransform()); psHist.Invalidate(); }
private void Refresh(object sender, EventArgs e) { _plotSurface.Clear(); _plotSurface.BackColor = Color.Black; if (!_component.ComputeHistogram()) { _plotSurface.Refresh(); return; } HistogramPlot histogram = new HistogramPlot(); histogram.AbscissaData = _component.BinLabels; histogram.OrdinateData = _component.Bins; histogram.Center = false; histogram.BaseWidth = 1.0f; histogram.Filled = true; histogram.Pen = new Pen(Application.CurrentUITheme.Colors.StandardColorBase); histogram.RectangleBrush = new RectangleBrushes.Solid(Application.CurrentUITheme.Colors.StandardColorBase); _plotSurface.Add(histogram); _plotSurface.PlotBackColor = Color.Black; _plotSurface.XAxis1.Color = Color.White; _plotSurface.YAxis1.Color = Color.White; _plotSurface.Refresh(); }
public HistogramSample() : base() { infoText = ""; infoText += "Gaussian Example. Demonstrates - \n"; infoText += " * HistogramPlot and LinePlot"; plotCanvas.Clear(); System.Random r = new Random(); int len = 35; double[] a = new double [len]; double[] b = new double [len]; for (int i = 0; i < len; ++i) { a[i] = Math.Exp(-(double)(i - len / 2) * (double)(i - len / 2) / 50.0); b[i] = a[i] + (r.Next(10) / 50.0f) - 0.05f; if (b[i] < 0) { b[i] = 0; } } HistogramPlot sp = new HistogramPlot(); sp.DataSource = b; sp.BorderColor = Colors.DarkBlue; sp.Filled = true; sp.FillColor = Colors.Gold; //Gradient (Colors.Lavender, Color.Gold ); sp.BaseWidth = 0.5; sp.Label = "Random Data"; LinePlot lp = new LinePlot(); lp.DataSource = a; lp.LineColor = Colors.Blue; lp.LineWidth = 3; lp.Label = "Gaussian Function"; plotCanvas.Add(sp); plotCanvas.Add(lp); plotCanvas.Legend = new Legend(); plotCanvas.YAxis1.WorldMin = 0.0; plotCanvas.Title = "Histogram Plot"; PackStart(plotCanvas.Canvas, true); Label la = new Label(infoText); PackStart(la); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { // this example will in the future demonstrate histogram plots with +- values. // currently not used - histograms don't support this. plotSurface.Clear(); int[] values = { -10, 2, -3, 4, 6, -1, 10, 4, -4, -3 }; HistogramPlot hp = new HistogramPlot(); hp.OrdinateData = values; plotSurface.Add(hp); plotSurface.Refresh(); }
public void AddRandomHistogramPlot(Graph graph) { Random random = new Random(); HistogramPlot plot = new HistogramPlot( CreateRandomModel(), GetRandomPlotColor()); plot.Name = "HistogramPlot"; plot.ShowValues = Convert.ToBoolean(random.Next(2)); plot.SetValueDataColumn(0, 0); plot.SetValueDataColumn(1, 1); graph.AddPlot(plot, graph.Axes); }
/// <summary> /// Constroi o Gráfico do tipo HistogramPlot /// </summary> /// <param name="graph"></param> /// <param name="sql"></param> public void HistogramPlot(Graph graph, DateTime date) { PlotColor plotColors = new PlotColor(); plotColors = PlotColor.Green; HistogramPlot plot = new HistogramPlot( CreateModel(date), plotColors); plot.Name = "Vendas por Mês"; plot.ShowValues = true; plot.SetValueDataColumn(0, 0); plot.SetValueDataColumn(1, 1); graph.AddPlot(plot, graph.Axes); }
public PlotGaussian() { infoText = ""; infoText += "Gaussian Example. Demonstrates - \n"; infoText += " * HistogramPlot and LinePlot."; plotSurface.Clear(); System.Random r = new Random(); int len = 35; double[] a = new double[len]; double[] b = new double[len]; for (int i = 0; i < len; ++i) { a[i] = (double)Math.Exp(-(double)(i - len / 2) * (double)(i - len / 2) / 50.0f); b[i] = a[i] + (r.Next(10) / 50.0f) - 0.05f; if (b[i] < 0.0f) { b[i] = 0; } } HistogramPlot sp = new HistogramPlot(); sp.DataSource = b; sp.Pen = Pens.DarkBlue; sp.Filled = true; sp.RectangleBrush = new RectangleBrushes.HorizontalCenterFade(Color.Lavender, Color.Gold); sp.BaseWidth = 0.5f; sp.Label = "Random Data"; LinePlot lp = new LinePlot(); lp.DataSource = a; lp.Pen = new Pen(Color.Blue, 3.0f); lp.Label = "Gaussian Function"; plotSurface.Add(sp); plotSurface.Add(lp); plotSurface.Legend = new Legend(); plotSurface.YAxis1.WorldMin = 0.0f; plotSurface.Title = "Histogram Plot"; plotSurface.Refresh(); }
public static void TestHistogramPlot() { // the PlotView is a WPF control that's created in the .xaml code OxyPlot.Wpf.PlotView examplePlotView = new OxyPlot.Wpf.PlotView(); int numBins = 10; // just some example data to plot var data = new List <Datum>() { new Datum(0), new Datum(0.75), new Datum(0), new Datum(0.5), new Datum(3), new Datum(3.5), new Datum(3), new Datum(3), new Datum(10), new Datum(10), }; // create the plot Plot plot = new HistogramPlot(examplePlotView, data, numBins, fillColor: OxyColors.Blue); // check to make sure the data was plotted Assert.That(plot.Model.Series.Count == 1); var series = plot.Model.Series[0]; var points = ((RectangleBarSeries)series).Items; Assert.That(points.Count == numBins); Assert.That(points[0].X0 == 0); // bin starts at 0 Assert.That(points[0].X1 == 1); // bin ends at 1 Assert.That(points[0].Y1 == 4); // 4 data points between 0 and 1 Assert.That(((RectangleBarSeries)series).ActualFillColor == OxyColors.Blue); }
private void button4_Click(object sender, EventArgs e) { myPlot.Clear(); HistogramPlot hp3 = new HistogramPlot(); hp3.AbscissaData = new int[] { 0, 1, 2 }; hp3.OrdinateData = new int[] { 4, 5, 6 }; hp3.BaseWidth = 0.6f; hp3.RectangleBrush = RectangleBrushes.Vertical.FaintBlueFade;//纵向渐变 hp3.Filled = true; hp3.Label = "一月"; HistogramPlot hp4 = new HistogramPlot(); hp4.AbscissaData = new int[] { 0, 1, 2 }; hp4.OrdinateData = new int[] { 7, 81, 9 }; hp4.Label = "二月"; hp4.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade;//横向渐变 hp4.Filled = true; hp4.StackedTo(hp3); myPlot.Add(hp3); myPlot.Add(hp4); myPlot.Refresh(); }
public static void TestEmptyDataCharts() { // the PlotView is a WPF control that's created in the .xaml code OxyPlot.Wpf.PlotView examplePlotView = new OxyPlot.Wpf.PlotView(); List <Datum> data = new List <Datum>(); Plot plot = new ScatterPlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); plot = new LinePlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); plot = new BarPlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); plot = new HistogramPlot(examplePlotView, data, 10); Assert.That(plot.Model.Series.Count == 0); plot = new SpectrumPlot(examplePlotView, data); Assert.That(plot.Model.Series.Count == 0); }
protected HistogramPlot CreatePlot(string title, int bins, List <double> values) { var max = values.Max(); var min = values.Min(); var binWidth = (max - min) / bins; if (Math.Abs(binWidth) < 1e-16) { bins = 1; binWidth = 0; } var plot = new HistogramPlot(title, OutputVariable, min, max, binWidth); for (var i = 1; i <= bins; i++) { plot.Bins[i] = new Bin { Value = (binWidth * (i - 1)) + min }; } foreach (var value in values) { int binIndex = binWidth != 0 ? (int)Math.Floor((value - min) / binWidth) + 1 : bins; if (binIndex > bins) { binIndex = bins; } plot.Bins[binIndex].Count += 1; } return(plot); }
public void InitDataToChart() { float min = (float)dataList[0]; //最小值 float max = (float)dataList[0]; //最大值 for (int i = 1; i < dataList.Count; i++) { if ((float)dataList[i] < min) { min = (float)dataList[i]; } if ((float)dataList[i] > max) { max = (float)dataList[i]; } } int start = (int)(min / 10) * 10; //x轴的起始值 int end = (int)Math.Ceiling(max / 10) * 10; //x轴的末尾值 int offset = 10; //x轴的偏移量 int size = (int)Math.Ceiling((float)(end - start) / offset); //计算柱状图中柱体的个数 double[] xValues = new double[size]; double[] yValues = new double[size]; for (int i = 0; i < size; i++) { xValues[i] = start + offset * i; } for (int i = 0; i < dataList.Count; i++) { int index = (int)(((float)dataList[i] - start) / offset); yValues[index]++; } for (int i = 0; i < size; i++) { yValues[i] = yValues[i] / dataList.Count * 100; } /*//图例 * legend = new Legend(); * legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left); * legend.VerticalEdgePlacement = Legend.Placement.Inside; * legend.HorizontalEdgePlacement = Legend.Placement.Outside; * legend.YOffset = -5; * legend.BorderStyle = LegendBase.BorderType.Line; * legend.NumberItemsHorizontally = 2; * legend.Font = new Font(FontFamily.GenericSerif, 8, FontStyle.Regular); * legend.AutoScaleText = false;*/ //网格 grid = new Grid(); grid.HorizontalGridType = Grid.GridType.Fine; grid.VerticalGridType = Grid.GridType.Fine; grid.MajorGridPen.Color = Color.Silver; grid.MinorGridPen.Color = Color.Silver; ///////////////////////////////////////////// //柱状图 histogramPlot = new HistogramPlot(); histogramPlot.AbscissaData = xValues; histogramPlot.OrdinateData = yValues; histogramPlot.RectangleBrush = new RectangleBrushes.Solid(Color.Orange); histogramPlot.Filled = true; histogramPlot.BaseWidth = 0.25f; //添加 chart.Add(grid); chart.Add(histogramPlot); // chart.XAxis1.Label = xLabel; chart.XAxis1.TicksCrossAxis = true; chart.YAxis1.Label = "%"; chart.YAxis1.WorldMin = 0; chart.YAxis1.LabelOffsetAbsolute = true; chart.Padding = 5; chart.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); // chart.PlotBackColor = Color.White; chart.BackColor = System.Drawing.SystemColors.Control; chart.XAxis1.Color = Color.Black; chart.YAxis1.Color = Color.Black; //chart.Legend = legend; chart.LegendZOrder = 1; chart.Refresh(); }
public PlotLabelAxis() { infoText = ""; infoText += "Internet Usage Example. Demonstrates - \n"; infoText += " * Label Axis with angled text. \n"; infoText += " * RectangleBrushes."; plotSurface.Clear(); Grid mygrid = new Grid(); mygrid.VerticalGridType = Grid.GridType.Coarse; Pen majorGridPen = new Pen(Color.LightGray); float[] pattern = { 1.0f, 2.0f }; majorGridPen.DashPattern = pattern; mygrid.MajorGridPen = majorGridPen; plotSurface.Add(mygrid); float[] xs = { 20.0f, 31.0f, 27.0f, 38.0f, 24.0f, 3.0f, 2.0f }; float[] xs2 = { 7.0f, 10.0f, 42.0f, 9.0f, 2.0f, 79.0f, 70.0f }; float[] xs3 = { 1.0f, 20.0f, 20.0f, 25.0f, 10.0f, 30.0f, 30.0f }; HistogramPlot hp = new HistogramPlot(); hp.DataSource = xs; hp.BaseWidth = 0.6f; hp.RectangleBrush = new RectangleBrushes.HorizontalCenterFade(Color.FromArgb(255, 255, 200), Color.White); hp.Filled = true; hp.Label = "Developer Work"; HistogramPlot hp2 = new HistogramPlot(); hp2.DataSource = xs2; hp2.Label = "Web Browsing"; hp2.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade; hp2.Filled = true; hp2.StackedTo(hp); HistogramPlot hp3 = new HistogramPlot(); hp3.DataSource = xs3; hp3.Label = "P2P Downloads"; hp3.RectangleBrush = RectangleBrushes.Vertical.FaintBlueFade; hp3.Filled = true; hp3.StackedTo(hp2); plotSurface.Add(hp); plotSurface.Add(hp2); plotSurface.Add(hp3); plotSurface.Legend = new Legend(); LabelAxis la = new LabelAxis(plotSurface.XAxis1); la.AddLabel("Monday", 0.0f); la.AddLabel("Tuesday", 1.0f); la.AddLabel("Wednesday", 2.0f); la.AddLabel("Thursday", 3.0f); la.AddLabel("Friday", 4.0f); la.AddLabel("Saturday", 5.0f); la.AddLabel("Sunday", 6.0f); la.Label = "Days"; la.TickTextFont = new Font("Courier New", 8); la.TicksBetweenText = true; plotSurface.XAxis1 = la; plotSurface.YAxis1.WorldMin = 0.0; plotSurface.YAxis1.Label = "MBytes"; ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 1; plotSurface.Title = "Internet useage for user:\n johnc 09/01/03 - 09/07/03"; plotSurface.XAxis1.TicksLabelAngle = 30.0f; plotSurface.PlotBackBrush = RectangleBrushes.Vertical.FaintRedFade; plotSurface.Refresh(); }
private void populateDataNPlot( List <string> arguments, List <string> series, List <List <object[]> > seriesValues, IList <object[]> argumentTotals, IList <object[]> seriesTotals, ReportSettings settings) { var chart = new PlotSurface2D { BackColor = SystemColors.Control, ForeColor = SystemColors.ControlText, PlotBackColor = SystemColors.Window, TitleColor = SystemColors.ControlText, SmoothingMode = SmoothingMode.HighQuality, Font = Font }; replaceChart(chart); if (arguments.Count == 0) { return; } var colorTransformation = new ColorSchemeTransformation(null) { IgnoreSaturation = true, AsBackground = true, }; var palette = _palette .Select(colorTransformation.TransformColor) .ToArray(); var summaryFields = settings.SummaryFields; chart.Legend = new Legend { BackgroundColor = SystemColors.Window, TextColor = SystemColors.WindowText, BorderColor = SystemColors.ActiveBorder }; chart.Legend.Font = chart.Legend.Font.ByDpi(); chart.Add(new Grid { VerticalGridType = Grid.GridType.Fine, HorizontalGridType = Grid.GridType.None, MinorGridPen = new Pen(SystemColors.GrayText) { DashPattern = new[] { 1f, 5f } }, MajorGridPen = new Pen(SystemColors.GrayText) }); var seriesSummaryLegend = new string[series.Count]; var argumentSummaryLegends = new List <string> [arguments.Count]; for (int i = 0; i < arguments.Count; i++) { argumentSummaryLegends[i] = new List <string>(); } var seriesList = new HistogramPlot[series.Count * summaryFields.Count]; float totalBarWidth = 0.75f; float barWidth = totalBarWidth / summaryFields.Count; double minY = double.MaxValue; double maxY = double.MinValue; var dataLabels = new List <TextItem>(); for (int k = 0; k < summaryFields.Count; k++) { float barOffset = (barWidth - totalBarWidth) * 0.5f + k * barWidth; string summaryFieldAlias = _fields.ByName[summaryFields[k]].Alias; string summaryFunctionAlias = Aggregates.Alias[settings.SummaryFunctions[k]]; var stackedYValues = new double[arguments.Count]; minY = Math.Min(0d, minY); maxY = Math.Max(0d, maxY); for (int j = 0; j < series.Count; j++) { int n = k * series.Count + j; Color color = palette[n % palette.Length]; var chartSeries = new HistogramPlot { Filled = true, RectangleBrush = new RectangleBrushes.Solid(color), BaseWidth = barWidth, BaseOffset = barOffset, Color = color, }; seriesList[n] = chartSeries; chart.Add(chartSeries); chartSeries.ShowInLegend = settings.ShowSeriesTotal; chartSeries.Label = series[j]; var yValues = Enumerable.Range(0, arguments.Count) .Select(i => Convert.ToDouble(seriesValues[j][i][k] ?? 0)) .ToList(); chartSeries.DataSource = yValues; for (int i = 0; i < arguments.Count; i++) { stackedYValues[i] += yValues[i]; } minY = Math.Min(minY, stackedYValues.Min()); maxY = Math.Max(maxY, stackedYValues.Max()); if (j > 0) { chartSeries.StackedTo(seriesList[n - 1]); } for (int i = 0; i < arguments.Count; i++) { double yValue = yValues[i]; if (yValue < 0.009) { continue; } string text; switch (settings.LabelDataElement) { case DataElement.SummaryField: text = $"{yValue:0.##}: {summaryFieldAlias}"; break; case DataElement.Series: text = $"{yValue:0.##}: {series[j]}"; break; case DataElement.Argument: text = $"{yValue:0.##}: {arguments[i]}"; break; case DataElement.SeriesAndArgument: text = $"{yValue:0.##}: {arguments[i]}, {series[j]}"; break; case DataElement.Values: text = $"{yValue:0.##}"; break; default: continue; } var labelY = stackedYValues[i] - yValue * 0.5; dataLabels.Add(new TextItem( new PointD(i + barOffset - 0.5f * barWidth + 0.05, labelY), text) { TextColor = SystemColors.ControlText, }); } } // if (settings.ShowSeriesTotal) // for (int j = 0; j < series.Count; j++) // { // string legend; // // bool seriesSet = settings.SeriesFields.Count > 1 || settings.SeriesFields[0] != string.Empty; // string seriesName; // if (seriesSet) // seriesName = series[j]; // else // seriesName = $"{summaryFunctionAlias} {summaryFieldAlias}"; // // if (settings.ExplainTotal && seriesSet) // legend = $"{seriesName}: {seriesTotals[j][k]}, {summaryFunctionAlias} {summaryFieldAlias}"; // else // legend = $"{seriesName}: {seriesTotals[j][k]}"; // // if (metadata.CanDisplayMultipleSeries) // seriesList[k * series.Count + j].LegendText = legend; // else // seriesSummaryLegend[j] = legend; // } // // if (settings.ShowArgumentTotal) // for (int i = 0; i < arguments.Count; i++) // { // string legend; // // if (settings.ExplainTotal) // legend = $"{arguments[i]}: {argumentTotals[i][k]}, {summaryFunctionAlias} {summaryFieldAlias}"; // else // legend = $"{arguments[i]}: {argumentTotals[i][k]}"; // // argumentSummaryLegends[i].Add(legend); // } } int largeTickStep = getLargeTickStep(maxY); chart.YAxis1 = new LinearAxis { WorldMin = minY, WorldMax = maxY + 0.5, LargeTickStep = largeTickStep, NumberOfSmallTicks = Math.Min(4, largeTickStep - 1), TickTextFont = Font, Color = SystemColors.WindowText, LabelColor = SystemColors.WindowText, TickTextColor = SystemColors.WindowText, }; var la = new LabelAxis { WorldMin = -0.5, WorldMax = arguments.Count - 0.5, TickTextFont = Font, Color = SystemColors.WindowText, LabelColor = SystemColors.WindowText, TickTextColor = SystemColors.WindowText, TickTextNextToAxis = false, TicksLabelAngle = 10f }; chart.XAxis1 = la; if (settings.ShowArgumentTotal) { var argumentSummaries = argumentSummaryLegends .Select(legends => string.Join("\n", legends)) .ToArray(); for (int i = 0; i < arguments.Count; i++) { la.AddLabel((arguments[i] + '\n' + argumentSummaries[i]).TrimEnd(), i); } } else { for (int i = 0; i < arguments.Count; i++) { la.AddLabel(arguments[i], i); } } foreach (TextItem label in dataLabels) { chart.Add(label); } }
public StackedHistogram() { infoText = ""; infoText += "Stacked Histogram Sample. Also demonstrates - \n"; infoText += " * Label Axis with angled text. \n"; infoText += " * ColorGradient Bars fill"; plotCanvas.Clear(); Grid myGrid = new Grid(); myGrid.VerticalGridType = Grid.GridType.Coarse; double[] pattern = { 1.0, 2.0 }; myGrid.MajorGridDash = pattern; myGrid.MajorGridColor = Colors.LightGray; plotCanvas.Add(myGrid); // set up Histogram dataSets manually double[] xs = { 20.0, 31.0, 27.0, 38.0, 24.0, 3.0, 2.0 }; double[] xs2 = { 7.0, 10.0, 42.0, 9.0, 2.0, 79.0, 70.0 }; double[] xs3 = { 1.0, 20.0, 20.0, 25.0, 10.0, 30.0, 30.0 }; HistogramPlot hp1 = new HistogramPlot(); hp1.DataSource = xs; hp1.BaseWidth = 0.6; hp1.FillGradient = new ColorGradient(Colors.LightGreen, Colors.White); hp1.Filled = true; hp1.Label = "Developer Work"; HistogramPlot hp2 = new HistogramPlot(); hp2.DataSource = xs2; hp2.Label = "Web Browsing"; hp2.FillGradient = new ColorGradient(Colors.LightBlue, Colors.White); hp2.Filled = true; hp2.StackedTo(hp1); HistogramPlot hp3 = new HistogramPlot(); hp3.DataSource = xs3; hp3.Label = "P2P Downloads"; hp3.FillGradient = new ColorGradient(Colors.Red, Colors.White); hp3.Filled = true; hp3.StackedTo(hp2); plotCanvas.Add(hp1); plotCanvas.Add(hp2); plotCanvas.Add(hp3); plotCanvas.Legend = new Legend(); LabelAxis la = new LabelAxis(plotCanvas.XAxis1); la.AddLabel("Monday", 0.0); la.AddLabel("Tuesday", 1.0); la.AddLabel("Wednesday", 2.0); la.AddLabel("Thursday", 3.0); la.AddLabel("Friday", 4.0); la.AddLabel("Saturday", 5.0); la.AddLabel("Sunday", 6.0); la.Label = "Days"; la.TickTextFont = Font.FromName("Courier New").WithSize(8); la.TicksBetweenText = true; plotCanvas.XAxis1 = la; plotCanvas.YAxis1.WorldMin = 0.0; plotCanvas.YAxis1.Label = "MBytes"; ((LinearAxis)plotCanvas.YAxis1).NumberOfSmallTicks = 1; plotCanvas.Title = "Internet useage for user:\n johnc 09/01/03 - 09/07/03"; plotCanvas.XAxis1.TickTextAngle = 30.0; PackStart(plotCanvas.Canvas, true); Label l = new Label(infoText); PackStart(l); }
public void Draw() { this.plot.PlotBackColor = Color.White; this.plot.BackColor = Color.White; ArrayList xs1 = new ArrayList(); ArrayList times = new ArrayList(); int split = 1; long lap = 0; float max = 0; float min = 32767 * 32767; long nlaps = 0; long totaltime = 0; this.plot.Clear(); if (((long[])splits[winner]).Length < nsplits) { return; } for (int i = nsplits; i < ((long[])splits[winner]).Length; ++i) { lap += ((long[])splits[winner])[i]; if (i != 0) { lap -= ((long[])splits[winner])[i - 1]; } if (split == nsplits) { //times.Add(" " + timetostr(lap)); string time = " " + timetostr(lap, true) + " : "; for (int s = nsplits - 1; s >= 0; --s) { if (i == nsplits && s == nsplits) { time += timetostr(((long[])splits[winner])[i - s], false); } else { time += timetostr(((long[])splits[winner])[i - s] - ((long[])splits[winner])[i - 1 - s], false); } if (s != 0) { time += " , "; } } time += " "; times.Add(time); totaltime += lap; ++nlaps; if (max < lap) { max = lap; } if (min > lap) { min = lap; } xs1.Add((double)lap); split = 1; lap = 0; } else { split++; } } if (nlaps != 0) { this.winner_avgtime = totaltime / nlaps; } if (nlaps == 0) { return; } Grid mygrid = new Grid(); mygrid.VerticalGridType = Grid.GridType.Coarse; mygrid.HorizontalGridType = Grid.GridType.Coarse; mygrid.MajorGridPen = new Pen(Color.LightGray, 1f); this.plot.Add(mygrid); for (int i = 0; i < xs1.Count; ++i) { double[] abscissa = { 0 }; double[] ordinate = { 0 }; if ((double)xs1[i] < winner_avgtime) { abscissa[0] = (i); ordinate[0] = ((double)xs1[i]) / 10000.0; HistogramPlot hp = new HistogramPlot(); hp.OrdinateData = ordinate; hp.AbscissaData = abscissa; hp.RectangleBrush = new RectangleBrushes.Horizontal(Color.FromArgb(106, 205, 84), Color.FromArgb(235, 255, 213)); hp.Pen.Color = Color.FromArgb(0, 150, 0); hp.Filled = true; hp.ShowInLegend = false; this.plot.Add(hp); } if ((double)xs1[i] >= winner_avgtime) { abscissa[0] = i; if (Settings.LimitLapTimes && (((double)xs1[i] - winner_avgtime) > (winner_avgtime - min) * Settings.LimitMultiplier)) { ordinate[0] = (winner_avgtime + (winner_avgtime - min) * Settings.LimitMultiplier) / 10000.0; } else { ordinate[0] = ((double)xs1[i]) / 10000.0; } HistogramPlot hp = new HistogramPlot(); hp.OrdinateData = ordinate; hp.AbscissaData = abscissa; if (Settings.LimitLapTimes && (((double)xs1[i] - winner_avgtime) > (winner_avgtime - min) * Settings.LimitMultiplier)) { hp.RectangleBrush = new RectangleBrushes.Horizontal(Color.FromArgb(190, 39, 92), Color.FromArgb(235, 124, 177)); } else { hp.RectangleBrush = new RectangleBrushes.Horizontal(Color.FromArgb(235, 84, 137), Color.FromArgb(255, 230, 210)); } hp.Pen.Color = Color.FromArgb(150, 0, 0); hp.Filled = true; hp.ShowInLegend = false; this.plot.Add(hp); } } //int xmax = ((long[])splits[winner]).Length / nsplits; LabelAxis la = new LabelAxis(this.plot.XAxis1); la.TicksBetweenText = false; la.TicksCrossAxis = false; la.LargeTickSize = 0; la.TickTextFont = Settings.lapTimesFont; for (int i = 0; i < times.Count; ++i) { la.AddLabel((string)times[i], i); } la.TicksLabelAngle = -90.0f; this.plot.XAxis1 = la; la = new LabelAxis((LabelAxis)la.Clone()); la.TicksBetweenText = false; la.TicksCrossAxis = true; la.LargeTickSize = 2; la.TicksLabelAngle = -90.0f; la.TickTextNextToAxis = false; la.TickTextFont = Settings.commonFont; for (int i = 0; i < times.Count; ++i) { la.AddLabel(System.Convert.ToString(i + 2), i); } la.LabelFont = Settings.commonFont; this.plot.XAxis2 = la; this.plot.YAxis1.TicksCrossAxis = true; this.plot.YAxis1.Label = ((string)this.players[this.player]); this.plot.YAxis1.LabelFont = Settings.titleFont; this.plot.YAxis1.LabelOffset = 20; this.plot.YAxis1.NumberFormat = ""; this.plot.YAxis1.TicksCrossAxis = false; if (Settings.LimitToGlobalBestLap) { this.plot.YAxis1.WorldMin = (double)this.bestlap / 10000.0; } ((LinearAxis)this.plot.YAxis1).NumberOfSmallTicks = 4; ((LinearAxis)this.plot.YAxis1).LargeTickStep = 1; ((LinearAxis)this.plot.YAxis1).TicksLabelAngle = -90f; HorizontalLine hl = new HorizontalLine((float)winner_avgtime / 10000, Color.Gray); hl.Pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; this.plot.Add(hl); this.laps = (int)nlaps; // this.plot.YAxis1.WorldMax += 1; if (this.plot.YAxis1.WorldMax - this.plot.YAxis1.WorldMin <= 0.1) { this.plot.YAxis1.WorldMax += 1; } this.plot.Refresh(); // System.Console.WriteLine(System.Convert.ToString(this.plot.YAxis1.WorldMin) + " " + System.Convert.ToString(this.plot.YAxis1.WorldMax)); }
static void Main(string[] args) { //string file = File.ReadAllText(@"C:\Users\abradu\Desktop\Personal\Flights\284F4A90C57F3FA3E04E364FE6ACB925.json"); string file = File.ReadAllText(@"C:\Users\abradu\Desktop\Personal\Flights\20056AD50DEFACE5A912E9076752BA70.json"); Blackbox bb = new JavaScriptSerializer().Deserialize <Blackbox>(file); bb.ConvertToNatives(); bb.SVT(); for (int i = 0; i < bb.altitude.Count; i++) { bb.altitude[i] = bb.altitude[i] / 1000; } NPlot.Bitmap.PlotSurface2D npSurface = new NPlot.Bitmap.PlotSurface2D(10000, 1000); NPlot.LinePlot npPlot1 = new LinePlot(); NPlot.LinePlot npPlot2 = new LinePlot(); NPlot.LinePlot npPlot3 = new LinePlot(); NPlot.LinePlot npPlot4 = new LinePlot(); NPlot.LinePlot npPlot5 = new LinePlot(); npSurface.Clear(); npSurface.Title = "Line Graph"; npSurface.BackColor = System.Drawing.Color.White; //Left Y axis grid: NPlot.Grid p = new Grid(); NPlot.HistogramPlot h = new HistogramPlot(); npSurface.Add(p, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Phi: npPlot1.AbscissaData = bb.time; npPlot1.DataSource = bb.angle_phi; npPlot1.Label = "Phi"; npPlot1.Color = System.Drawing.Color.Blue; npSurface.Add(npPlot1, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Phi: npPlot2.AbscissaData = bb.time; npPlot2.DataSource = bb.angle_psi; npPlot2.Label = "Psi"; npPlot2.Color = System.Drawing.Color.Red; npSurface.Add(npPlot2, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Theta: npPlot3.AbscissaData = bb.time; npPlot3.DataSource = bb.angle_theta; npPlot3.Label = "Theta"; npPlot3.Color = System.Drawing.Color.Green; npSurface.Add(npPlot3, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); //Speed: npPlot4.AbscissaData = bb.time; npPlot4.DataSource = bb.SpeedVsTheta; npPlot4.Label = "Speed"; npPlot4.Color = System.Drawing.Color.Black; npSurface.Add(npPlot4, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); ////Alti: //npPlot5.AbscissaData = bb.time; //npPlot5.DataSource = bb.altitude; //npPlot5.Label = "Alt"; //npPlot5.Color = System.Drawing.Color.Orange; //npSurface.Add(npPlot5, NPlot.PlotSurface2D.XAxisPosition.Bottom, // NPlot.PlotSurface2D.YAxisPosition.Left); npSurface.Refresh(); MemoryStream memStream = new MemoryStream(); npSurface.Bitmap.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif); FileStream fs = new FileStream(@"D:\file.gif", FileMode.Create); memStream.WriteTo(fs); //Console.WriteLine("Done"); //Console.ReadLine(); }