private void chart2_InteractionOccured(object sender) { LinearAxis axis1 = new LinearAxis(chart2.XAxis1); axis1.Label = ""; axis1.HideTickText = true; this.chart1.XAxis1 = axis1; this.chart1.Refresh(); LabelAxis axis2 = new LabelAxis(chart2.XAxis1); int tick = 1; if (chart2.XAxis1.WorldMax - chart2.XAxis1.WorldMin > 30) { tick = 2; } for (int i = (int)chart2.XAxis1.WorldMin; i <= chart2.XAxis1.WorldMax; i += tick) { int j = i % 24; if (j < 0) { j += 24; } axis2.AddLabel(Convert.ToString(j), i); } axis2.Label = "Time:Hour"; axis2.HideTickText = false; chart3.XAxis1 = axis2; this.chart3.Refresh(); SetStatusNow(); }
private void initialize(double[] x, double[] y, int[] z) { this.XAxis = x; this.YAxis = y; this.LabelAxis = z; if (z == null) { LabelValues = new int[] { }; } else { LabelValues = LabelAxis.Distinct(); } LabelNames = new string[LabelValues.Length]; for (int i = 0; i < LabelNames.Length; i++) { LabelNames[i] = i.ToString(); } var classes = new ScatterplotClassValueCollection[LabelValues.Length]; for (int i = 0; i < classes.Length; i++) { classes[i] = new ScatterplotClassValueCollection(this, i); } Classes = new ReadOnlyCollection <ScatterplotClassValueCollection>(classes); }
private void initialize(double[] x, double[] y, int[] z) { this.XAxis = x; this.YAxis = y; this.LabelAxis = z; LabelValues = LabelAxis.Distinct().ToArray(); ScatterplotClassValueCollection[] classes = new ScatterplotClassValueCollection[LabelValues.Length]; for (int i = 0; i < classes.Length; i++) { classes[i] = new ScatterplotClassValueCollection(this, i); } Classes = new ReadOnlyCollection <ScatterplotClassValueCollection>(classes); }
private void button12_Click(object sender, EventArgs e) { LabelAxis la1 = new LabelAxis(this.myPlot.XAxis1); string[] sX = new string[5] { "a", "b", "c", "d", "e" }; for (int i = 0; i < 5; i++) { la1.AddLabel(sX[i].ToString(), i); } la1.Label = "时间"; la1.TickTextFont = new Font("Courier New", 10); la1.TicksBetweenText = false; this.myPlot.XAxis1 = la1; }
private static void DoDurationChartDemo(ElementPosition xAxisPositioning, ElementPosition yAxisPositioning) { DurationChart durationChart = new DurationChart(); durationChart.Title = "Production ETL Loads"; durationChart.SubTitle = "28/09 to 03/10 (midday)"; durationChart.OutputFile = @"C:\New Folder\aDemo-duration-chart-" + xAxisPositioning.ToString() + "-" + yAxisPositioning.ToString() + ".png"; durationChart.BarShape = BarShape.ROUNDED_RECTANGLE; durationChart.LoadDataPointsFromCSV(@"C:\New folder\etllog.csv", new DateTime(2020, 9, 30, 0, 0, 0), new DateTime(2020, 10, 1, 11, 0, 0)); var xAxis = new DateAndTimeScaleAxis(new DateTime(2020, 9, 30, 0, 0, 0), new DateTime(2020, 10, 1, 11, 0, 0), 60, 10, 10, AxisLabelFormat.DATETIME_DDMMYYYY1_HHMM24); xAxis.MajorGridLine = true; xAxis.LabelHorizontalPosition = AxisLabelHorizontalPosition.CENTER; durationChart.SetXAxis(xAxisPositioning, xAxis, AxisWidth.FIT_TO_INCREMENT, 90); var yAxis = new LabelAxis(30, durationChart.GetDataSeriesNames()); yAxis.MajorGridLine = true; yAxis.AlternatingMajorGridLines = true; durationChart.SetY1Axis(yAxisPositioning, yAxis, AxisWidth.FIT_TO_INCREMENT); durationChart.ChartLegend.IsLegendVisible = true; durationChart.ChartLegend.Layout = LegendLayout.HORIZONTAL; durationChart.ChartLegend.AddEntry(new LegendEntry(LegendDisplayType.SQUARE, Color.CornflowerBlue, "Successful Run")); durationChart.ChartLegend.AddEntry(new LegendEntry(LegendDisplayType.SQUARE, Color.Red, "Failed Run")); durationChart.ConfigureContractionsOnXAxis(2, true, true); //durationChart.DetectContractions(2, xAxis); /* Console.WriteLine($"Checking between 7 and 8 am: {durationChart.HasData(new DateTime(2020, 9, 30, 7, 0, 0), new DateTime(2020, 9, 30, 8, 0, 0))}"); * Console.WriteLine($"Checking between 8 and 9 am: {durationChart.HasData(new DateTime(2020, 9, 30, 8, 0, 0), new DateTime(2020, 9, 30, 9, 0, 0))}"); * Console.WriteLine($"Checking between 9 and 10 am: {durationChart.HasData(new DateTime(2020, 9, 30, 9, 0, 0), new DateTime(2020, 9, 30, 10, 0, 0))}"); * Console.WriteLine($"Checking between 10 and 11 am: {durationChart.HasData(new DateTime(2020, 9, 30, 10, 0, 0), new DateTime(2020, 9, 30, 11, 0, 0))}"); * Console.WriteLine($"Checking between 11 and 12: {durationChart.HasData(new DateTime(2020, 9, 30, 11, 0, 0), new DateTime(2020, 9, 30, 8, 12, 0))}"); * Console.WriteLine($"Checking between 12 and 1 pm: {durationChart.HasData(new DateTime(2020, 9, 30, 12, 0, 0), new DateTime(2020, 9, 30, 13, 0, 0))}"); * Console.WriteLine($"Checking between 1 and 2 pm: {durationChart.HasData(new DateTime(2020, 9, 30, 13, 0, 0), new DateTime(2020, 9, 30, 14, 0, 0))}");*/ durationChart.GenerateChart(); }
public PlotMockup() { infoText = ""; infoText += "THE TEST (can your charting library handle this?) - \n"; infoText += "NPlot demonstrates it can handle real world charting requirements."; // first of all, generate some mockup data. DataTable info = new DataTable("Store Information"); info.Columns.Add("Index", typeof(int)); info.Columns.Add("IndexOffsetLeft", typeof(float)); info.Columns.Add("IndexOffsetRight", typeof(float)); info.Columns.Add("StoreName", typeof(string)); info.Columns.Add("BarBase", typeof(float)); info.Columns.Add("StoreGrowth", typeof(float)); info.Columns.Add("AverageGrowth", typeof(float)); info.Columns.Add("ProjectedSales", typeof(float)); float barBase = 185.0f; Random r = new Random(); for (int i = 0; i < 18; ++i) { DataRow row = info.NewRow(); row["Index"] = i; row["IndexOffsetLeft"] = (float)i - 0.1f; row["IndexOffsetRight"] = (float)i + 0.1f; row["StoreName"] = "Store " + (i + 1).ToString(); row["BarBase"] = barBase; row["StoreGrowth"] = barBase + ((r.NextDouble() - 0.1) * 20.0f); row["AverageGrowth"] = barBase + ((r.NextDouble() - 0.1) * 15.0f); row["ProjectedSales"] = barBase + (r.NextDouble() * 15.0f); info.Rows.Add(row); barBase += (float)r.NextDouble() * 4.0f; } plotSurface.Clear(); plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // generate the grid Grid grid = new Grid(); grid.VerticalGridType = Grid.GridType.Coarse; grid.HorizontalGridType = Grid.GridType.None; grid.MajorGridPen = new Pen(Color.Black, 1.0f); plotSurface.Add(grid); // generate the trendline LinePlot trendline = new LinePlot(); trendline.DataSource = info; trendline.AbscissaData = "Index"; trendline.OrdinateData = "BarBase"; trendline.Pen = new Pen(Color.Black, 3.0f); trendline.Label = "Trendline"; plotSurface.Add(trendline); // draw store growth bars BarPlot storeGrowth = new BarPlot(); storeGrowth.DataSource = info; storeGrowth.AbscissaData = "IndexOffsetLeft"; storeGrowth.OrdinateDataTop = "StoreGrowth"; storeGrowth.OrdinateDataBottom = "BarBase"; storeGrowth.Label = "Store Growth"; storeGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Black; //storeGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(storeGrowth); // draw average growth bars BarPlot averageGrowth = new BarPlot(); averageGrowth.DataSource = info; averageGrowth.AbscissaData = "IndexOffsetRight"; averageGrowth.OrdinateDataBottom = "BarBase"; averageGrowth.OrdinateDataTop = "AverageGrowth"; averageGrowth.Label = "Average Growth"; averageGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Gray; //averageGrowth.BorderPen = new Pen( Color.Black, 2.0f ); plotSurface.Add(averageGrowth); // generate the projected sales step line. StepPlot projected = new StepPlot(); projected.DataSource = info; projected.AbscissaData = "Index"; projected.OrdinateData = "ProjectedSales"; projected.Pen = new Pen(Color.Orange, 3.0f); projected.HideVerticalSegments = true; projected.Center = true; projected.Label = "Projected Sales"; projected.WidthScale = 0.7f; plotSurface.Add(projected); // generate the minimum target line. HorizontalLine minimumTargetLine = new HorizontalLine(218, new Pen(Color.Green, 3.5f)); minimumTargetLine.Label = "Minimum Target"; minimumTargetLine.LengthScale = 0.98f; minimumTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(minimumTargetLine); // generate the preferred target line. HorizontalLine preferredTargetLine = new HorizontalLine(228, new Pen(Color.Blue, 3.5f)); preferredTargetLine.Label = "Preferred Target"; preferredTargetLine.LengthScale = 0.98f; preferredTargetLine.ShowInLegend = true; // off by default for lines. plotSurface.Add(preferredTargetLine); // make some modifications so that chart matches requirements. // y axis. plotSurface.YAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.YAxis1.TickTextNextToAxis = false; //plotSurface.YAxis1.TicksAngle = 3.0f * (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed ((LinearAxis)plotSurface.YAxis1).LargeTickStep = 10.0; ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 0; // x axis plotSurface.XAxis1.TicksIndependentOfPhysicalExtent = true; plotSurface.XAxis1.TickTextNextToAxis = false; //plotSurface.XAxis1.TicksAngle = (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed LabelAxis la = new LabelAxis(plotSurface.XAxis1); for (int i = 0; i < info.Rows.Count; ++i) { la.AddLabel((string)info.Rows[i]["StoreName"], Convert.ToInt32(info.Rows[i]["Index"])); } la.TicksLabelAngle = (float)90.0f; la.TicksBetweenText = true; plotSurface.XAxis1 = la; plotSurface.XAxis2 = (Axis)plotSurface.XAxis1.Clone(); plotSurface.XAxis2.HideTickText = true; plotSurface.XAxis2.LargeTickSize = 0; Legend l = new Legend(); l.NumberItemsVertically = 2; l.AttachTo(XAxisPosition.Bottom, YAxisPosition.Left); l.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside; l.VerticalEdgePlacement = NPlot.Legend.Placement.Inside; l.XOffset = 5; l.YOffset = 50; l.BorderStyle = NPlot.LegendBase.BorderType.Line; plotSurface.Legend = l; plotSurface.Title = "Sales Growth Compared to\n" + "Average Sales Growth by Store Size - Rank Order Low to High"; plotSurface.Refresh(); }
public void setText(string[] texts, Vector2 orgpos, LabelAxis axis, float merginscale, bool resize=true) { int r = 1, c = 1; int h =1,v=1; switch (axis) { case LabelAxis.HOLIZONTAL: c = texts.Length; v = 0; break; case LabelAxis.VERTICAL: r = texts.Length; h = 0; break; } Debug.LogFormat("R:{0}, C:{1}, H:{2}, V:{3}",r,c,h,v); WindowText[,] newtexts = new WindowText[r, c]; Vector2 mergin = Vector2.zero; int idx = 0; int strlength = 0; for (int x = 0; x < c; x++) { for (int y = 0; y < r; y++) { if (idx > 0) strlength = texts.Length; mergin = WindowConfigure.createFontScaleForVector((strlength+merginscale)*h,idx*v*merginscale); newtexts[y, x] = new WindowText(texts[idx],orgpos + mergin); idx++; } } setText(newtexts); if (resize) { float width = 1, height = 1; switch (axis) { case LabelAxis.HOLIZONTAL: int sum = texts.Sum(str => str.Length); width = sum; break; case LabelAxis.VERTICAL: height = r; width = texts.Max(str => str.Length); break; } Vector2 size = WindowConfigure.createFontScaleForVector(width*merginscale,height*merginscale*1.15f); WindowSize = size; init(); } }
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 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)); }
/////////K线图绘制////////// public void PlotCandle(CandlePlot cp, List <DateTime> dates, trader.KLine.TimeFrame timeframe) { try { myPlot.Clear(); // --- Grid Code --- Grid mygrid = new Grid(); mygrid.HorizontalGridType = Grid.GridType.Fine; mygrid.VerticalGridType = Grid.GridType.Fine; myPlot.Add(mygrid); cp.BullishColor = Color.Red; //cp.Color = Color.Black; cp.Centered = false; cp.BearishColor = Color.Green; cp.Style = CandlePlot.Styles.Filled; this.myPlot.Add(cp); //////这里需要先添加图形后设置坐标轴 /////字符坐标轴加入后会隐藏原来的x坐标轴 LabelAxis la1 = new LabelAxis(this.myPlot.XAxis1); for (int i = 0; i < dates.Count; i++) { switch (timeframe) { case trader.KLine.TimeFrame.M1: if (Math.IEEERemainder(i, 30) == 0) { la1.AddLabel(dates[i].ToShortTimeString() + @" " + dates[i].ToShortDateString(), i); } break; case trader.KLine.TimeFrame.M5: if (Math.IEEERemainder(i, 12) == 0) { la1.AddLabel(dates[i].ToShortTimeString() + @" " + dates[i].ToShortDateString(), i + 00); } break; default: if (Math.IEEERemainder(i, 5) == 0) { la1.AddLabel(dates[i].ToShortTimeString() + @" " + dates[i].ToShortDateString(), i + 00); } break; } } //la1.Label = "时间"; la1.TickTextFont = new Font("Courier New", 8); la1.TicksBetweenText = false; this.myPlot.XAxis1 = la1; //////让日期斜45度。 //myPlot.XAxis1.TicksLabelAngle = 45; myPlot.Refresh(); } catch (Exception e) { //Console.WriteLine("{0} Exception caught.", e); //MessageBox.Show(e.ToString()); } }
public PlotQE() { infoText = ""; infoText += "Cs2Te Photocathode QE evolution Example. Demonstrates - \n"; infoText += " * LabelPointPlot (allows text to be associated with points) \n"; infoText += " * PointPlot droplines \n"; infoText += " * LabelAxis \n"; infoText += " * PhysicalSpacingMin property of LabelAxis \n"; infoText += "You cannot interact with this chart"; // This doesn't currently work, as the Timer is not in a Window qeExampleTimer = new System.Windows.Forms.Timer(); qeExampleTimer.Interval = 500; qeExampleTimer.Tick += new EventHandler(qeExampleTimer_Tick); qeExampleTimerEnabled = true; plotSurface.Clear(); int len = 24; string[] s = new string[len]; PlotQEExampleValues = new double[len]; PlotQEExampleTextValues = new string[len]; Random r = new Random(); for (int i = 0; i < len; i++) { PlotQEExampleValues[i] = 8.0f + 12.0f * (double)r.Next(10000) / 10000.0f; if (PlotQEExampleValues[i] > 18.0f) { PlotQEExampleTextValues[i] = "KCsTe"; } else { PlotQEExampleTextValues[i] = ""; } s[i] = i.ToString("00") + ".1"; } PointPlot pp = new PointPlot(); pp.DataSource = PlotQEExampleValues; pp.Marker = new Marker(Marker.MarkerType.Square, 10); pp.Marker.DropLine = true; pp.Marker.Pen = Pens.CornflowerBlue; pp.Marker.Filled = false; plotSurface.Add(pp); LabelPointPlot tp1 = new LabelPointPlot(); tp1.DataSource = PlotQEExampleValues; tp1.TextData = PlotQEExampleTextValues; tp1.LabelTextPosition = LabelPointPlot.LabelPositions.Above; tp1.Marker = new Marker(Marker.MarkerType.None, 10); plotSurface.Add(tp1); LabelAxis la = new LabelAxis(plotSurface.XAxis1); for (int i = 0; i < len; ++i) { la.AddLabel(s[i], i); } FontFamily ff = new FontFamily("Verdana"); la.TickTextFont = new Font(ff, 7); la.PhysicalSpacingMin = 25; plotSurface.XAxis1 = la; plotSurface.Title = "Cs2Te Photocathode QE evolution"; plotSurface.TitleFont = new Font(ff, 15); plotSurface.XAxis1.WorldMin = -1.0f; plotSurface.XAxis1.WorldMax = len; plotSurface.XAxis1.LabelFont = new Font(ff, 10); plotSurface.XAxis1.Label = "Cathode ID"; plotSurface.YAxis1.Label = "QE [%]"; plotSurface.YAxis1.LabelFont = new Font(ff, 10); plotSurface.YAxis1.TickTextFont = new Font(ff, 10); plotSurface.YAxis1.WorldMin = 0.0; plotSurface.YAxis1.WorldMax = 25.0; plotSurface.XAxis1.TicksLabelAngle = 60.0f; plotSurface.Refresh(); }
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 LabelPointPlotSample() { infoText = ""; infoText += "Cs2Te Photocathode QE evolution Example. Demonstrates - \n"; infoText += " * LabelPointPlot (allows text to be associated with points) \n"; infoText += " * PointPlot droplines \n"; infoText += " * LabelAxis \n"; infoText += " * PhysicalSpacingMin property of LabelAxis \n"; qeExampleTimerEnabled = true; plotCanvas.Clear(); int len = 24; string[] s = new string[len]; PlotQEExampleValues = new double[len]; PlotQEExampleTextValues = new string[len]; Random r = new Random(); for (int i = 0; i < len; i++) { PlotQEExampleValues[i] = 8.0 + 12.0 * (double)r.Next(10000) / 10000.0; if (PlotQEExampleValues[i] > 18.0) { PlotQEExampleTextValues[i] = "KCsTe"; } else { PlotQEExampleTextValues[i] = ""; } s[i] = i.ToString("00") + ".1"; } PointPlot pp = new PointPlot(); pp.DataSource = PlotQEExampleValues; pp.Marker = new Marker(Marker.MarkerType.Square, 10); pp.Marker.DropLine = true; pp.Marker.LineColor = Colors.CornflowerBlue; pp.Marker.Filled = false; plotCanvas.Add(pp); LabelPointPlot tp1 = new LabelPointPlot(); tp1.DataSource = PlotQEExampleValues; tp1.TextData = PlotQEExampleTextValues; tp1.LabelTextPosition = LabelPointPlot.LabelPositions.Above; tp1.Marker = new Marker(Marker.MarkerType.None, 10); plotCanvas.Add(tp1); LabelAxis la = new LabelAxis(plotCanvas.XAxis1); for (int i = 0; i < len; ++i) { la.AddLabel(s[i], i); } Font ff = Font.FromName("Verdana"); la.TickTextFont = ff.WithSize(7); la.PhysicalSpacingMin = 25; plotCanvas.XAxis1 = la; plotCanvas.Title = "Cs2Te Photocathode QE evolution"; plotCanvas.TitleFont = ff.WithSize(15); plotCanvas.XAxis1.WorldMin = -1.0; plotCanvas.XAxis1.WorldMax = len; plotCanvas.XAxis1.LabelFont = ff.WithSize(10); plotCanvas.XAxis1.Label = "Cathode ID"; plotCanvas.YAxis1.Label = "QE [%]"; plotCanvas.YAxis1.LabelFont = ff.WithSize(10); plotCanvas.YAxis1.TickTextFont = ff.WithSize(10); plotCanvas.YAxis1.WorldMin = 0.0; plotCanvas.YAxis1.WorldMax = 25.0; plotCanvas.XAxis1.TickTextAngle = 60.0; // Add timer into Xwt loop for data updates Application.TimeoutInvoke(750, qeExampleTimer_Tick); PackStart(plotCanvas.Canvas, true); Label info = new Label(infoText); PackStart(info); }
public void InitDataToChart() { //清空 chart1.Clear(); chart2.Clear(); chart3.Clear(); //垂直线 vline = new VerticalLine(0, Color.Blue); //图例 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 = 4; //网格 grid = new Grid(); grid.HorizontalGridType = Grid.GridType.Fine; grid.VerticalGridType = Grid.GridType.Fine; grid.MajorGridPen.Color = Color.Silver; grid.MinorGridPen.Color = Color.Silver; /////区域着色//////// fill = new FilledRegion(new VerticalLine(-1), new VerticalLine(8)); fill.Brush = new SolidBrush(Color.FromArgb(250, 218, 169)); ///////////////////////////////////////////// //直线图 sysPlot = new LinePlot(); sysPlot.OrdinateData = sysList; sysPlot.AbscissaData = timeList; sysPlot.Color = Color.RoyalBlue; sysPlot.Pen.Width = 2.0f; sysPlot.Label = "SYS"; diaPlot = new LinePlot(); diaPlot.OrdinateData = diaList; diaPlot.AbscissaData = timeList; diaPlot.Color = Color.OrangeRed; diaPlot.Pen.Width = 2.0f; diaPlot.Label = "DIA"; mapPlot = new LinePlot(); mapPlot.OrdinateData = mapList; mapPlot.AbscissaData = timeList; mapPlot.Color = Color.Chartreuse; mapPlot.Pen.Width = 2.0f; mapPlot.Label = "MAP"; hrPlot = new LinePlot(); hrPlot.OrdinateData = hrList; hrPlot.AbscissaData = timeList; hrPlot.Color = Color.DarkSlateBlue; hrPlot.Pen.Width = 2.0f; sys_hrPlot = new LinePlot(); sys_hrPlot.OrdinateData = sys_hrList; sys_hrPlot.AbscissaData = timeList; sys_hrPlot.Color = Color.Green; sys_hrPlot.Pen.Width = 2.0f; //水平线 hline1 = new HorizontalLine(70, Color.Gray); hline2 = new HorizontalLine(90, Color.Gray); hline3 = new HorizontalLine(120, Color.Gray); hline4 = new HorizontalLine(140, Color.Gray); /////////////////////// chart1.Add(fill); chart1.Add(grid); chart1.Add(sysPlot); chart1.Add(diaPlot); chart1.Add(mapPlot); chart1.Add(hline1); chart1.Add(hline2); chart1.Add(hline3); chart1.Add(hline4); chart1.Add(vline); chart1.XAxis1.HideTickText = true; chart1.YAxis1.Label = "血压:mmHg"; chart1.YAxis1.LabelOffsetAbsolute = true; chart1.YAxis1.WorldMin = chart1.YAxis1.WorldMin - 20; chart1.YAxis1.WorldMax = chart1.YAxis1.WorldMax + 20; chart1.Padding = 5; chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag()); chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag()); chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart1.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); chart1.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart1_InteractionOccured); chart1.PlotBackColor = Color.White; chart1.BackColor = System.Drawing.SystemColors.Control; chart1.XAxis1.Color = Color.Black; chart1.YAxis1.Color = Color.Black; chart1.Legend = legend; chart1.LegendZOrder = 1; chart1.Refresh(); /////////////////////////// chart2.Add(fill); chart2.Add(grid); chart2.Add(hrPlot); chart2.Add(vline); chart2.XAxis1.HideTickText = true; chart2.YAxis1.Label = "心率:BPM"; chart2.YAxis1.LabelOffsetAbsolute = true; chart2.Padding = 5; chart2.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag()); chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag()); chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart2.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart2_InteractionOccured); chart2.PlotBackColor = Color.White; chart2.BackColor = System.Drawing.SystemColors.Control; chart2.XAxis1.Color = Color.Black; chart2.YAxis1.Color = Color.Black; chart2.Refresh(); /////////////////////////// chart3.Add(fill); chart3.Add(grid); chart3.Add(sys_hrPlot); chart3.Add(vline); LabelAxis axis = new LabelAxis(chart3.XAxis1); int tick = 1; if (chart2.XAxis1.WorldMax - chart2.XAxis1.WorldMin > 30) { tick = 2; } for (int i = (int)chart2.XAxis1.WorldMin; i <= chart2.XAxis1.WorldMax; i += tick) { int j = i % 24; if (j < 0) { j += 24; } axis.AddLabel(Convert.ToString(j), i); } chart3.XAxis1 = axis; chart3.XAxis1.Label = "Time:Hour"; chart3.YAxis1.Label = "SYS*PR/100"; chart3.YAxis1.LabelOffsetAbsolute = true; chart3.Padding = 5; chart3.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag()); chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag()); chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart3.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart3_InteractionOccured); chart3.PlotBackColor = Color.White; chart3.BackColor = System.Drawing.SystemColors.Control; chart3.XAxis1.Color = Color.Black; chart3.YAxis1.Color = Color.Black; chart3.Refresh(); SetStatusNow(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { this.plotSurface = plotSurface; this.Timer = new System.Timers.Timer(); this.Timer.Interval = 500; this.Timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed); this.Timer.Enabled = true; plotSurface.Clear(); int len = 24; string[] s = new string[len]; PlotQEExampleValues = new double[len]; PlotQEExampleTextValues = new string[len]; Random r = new Random(); for (int i = 0; i < len; i++) { PlotQEExampleValues[i] = 8.0f + 12.0f * (double)r.Next(10000) / 10000.0f; if (PlotQEExampleValues[i] > 18.0f) { PlotQEExampleTextValues[i] = "KCsTe"; } else { PlotQEExampleTextValues[i] = ""; } s[i] = i.ToString("00") + ".1"; } PointPlot pp = new PointPlot(); pp.DataSource = PlotQEExampleValues; pp.Marker = new Marker(Marker.MarkerType.Square, 10); pp.Marker.DropLine = true; pp.Marker.Pen = Pens.CornflowerBlue; pp.Marker.Filled = false; plotSurface.Add(pp); LabelPointPlot tp1 = new LabelPointPlot(); tp1.DataSource = PlotQEExampleValues; tp1.TextData = PlotQEExampleTextValues; tp1.LabelTextPosition = LabelPointPlot.LabelPositions.Above; tp1.Marker = new Marker(Marker.MarkerType.None, 10); plotSurface.Add(tp1); LabelAxis la = new LabelAxis(plotSurface.XAxis1); for (int i = 0; i < len; ++i) { la.AddLabel(s[i], i); } FontFamily ff = new FontFamily("Verdana"); la.TickTextFont = new Font(ff, 7); la.PhysicalSpacingMin = 25; plotSurface.XAxis1 = la; plotSurface.Title = "Cs2Te Photocathode QE evolution"; plotSurface.TitleFont = new Font(ff, 15); plotSurface.XAxis1.WorldMin = -1.0f; plotSurface.XAxis1.WorldMax = len; plotSurface.XAxis1.LabelFont = new Font(ff, 10); plotSurface.XAxis1.Label = "Cathode ID"; plotSurface.YAxis1.Label = "QE [%]"; plotSurface.YAxis1.LabelFont = new Font(ff, 10); plotSurface.YAxis1.TickTextFont = new Font(ff, 10); plotSurface.YAxis1.WorldMin = 0.0; plotSurface.YAxis1.WorldMax = 25.0; plotSurface.XAxis1.TicksLabelAngle = 60.0f; plotSurface.Refresh(); }