Пример #1
0
 public void InitDataToChart()
 {
     //图例
     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;
     /////////////////////////////////////////////
     //直线图
     linePlot = new LinePlot();
     linePlot.OrdinateData = cart.regressY;
     linePlot.AbscissaData = xList;
     linePlot.Color = Color.Orange;
     linePlot.Pen.Width = 2.0f;
     //点图
     Marker marker = new Marker(Marker.MarkerType.FilledCircle, 3, new Pen(Color.Blue));
     marker.FillBrush = new SolidBrush(Color.RoyalBlue);
     pointPlot = new PointPlot(marker);
     pointPlot.AbscissaData = xList;
     pointPlot.OrdinateData = yList;
     pointPlot.ShowInLegend = false;
     if(cart.regressXYB>0)
         linePlot.Label = yLabel + "=" + cart.regressXYA.ToString("F2") + "*" + xLabel + "+" + cart.regressXYB.ToString("F2")
             + ",R=" + cart.correlationXY.ToString("F2");
     else
         linePlot.Label = yLabel + "=" + cart.regressXYA.ToString("F2") + "*" + xLabel + cart.regressXYB.ToString("F2")
             + ",R=" + cart.correlationXY;
     label1.Text = xLabel + "(m:" + cart.xMean.ToString("F1") + ",s':" + cart.xVar.ToString("F1")
         + ")  " + yLabel + "(m:" + cart.yMean.ToString("F1") + ",s':" + cart.yVar.ToString("F1") + ")";
     //添加
     chart.Add(grid);
     chart.Add(linePlot);
     chart.Add(pointPlot);
     //设置属性
     chart.XAxis1.Label = xLabel+":"+xUnit;
     chart.YAxis1.Label = yLabel+":"+yUnit;
     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();
 }
        private void PlotSincFunction()
        {
            string lines = "Sinc Function Example. Demonstrates -  * Charting line and point plot at the same time. * Adding a legend.";
            infoBox.Text = lines;

            plotSurface.Clear(); // clear everything. reset fonts. remove plot components etc.

            System.Random r = new Random();
            double[] a = new double[100];
            double[] b = new double[100];
            double mult = 0.00001f;
            for( int i=0; i<100; ++i )
            {
                a[i] = ((double)r.Next(1000)/5000.0f-0.1f)*mult;
                if (i == 50 ) { b[i] = 1.0f*mult; }
                else
                {
                    b[i] = (double)Math.Sin((((double)i-50.0f)/4.0f))/(((double)i-50.0f)/4.0f);
                    b[i] *= mult;
                }
                a[i] += b[i];
            }

            Marker m = new Marker(Marker.MarkerType.Cross1,6,new Pen(Color.Blue,2.0F));
            PointPlot pp = new PointPlot( m );
            pp.OrdinateData = a;
            pp.AbscissaData = new StartStep( -500.0, 10.0 );
            pp.Label = "Random";
            plotSurface.Add(pp);

            LinePlot lp = new LinePlot();
            lp.OrdinateData = b;
            lp.AbscissaData = new StartStep( -500.0, 10.0 );
            lp.Pen = new Pen( Color.Red, 2.0f );
            plotSurface.Add(lp);

            plotSurface.Title = "Sinc Function";
            plotSurface.YAxis1.Label = "Magnitude";
            plotSurface.XAxis1.Label = "Position";

            Legend legend = new Legend();
            legend.AttachTo( PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left );
            legend.VerticalEdgePlacement = Legend.Placement.Inside;
            legend.HorizontalEdgePlacement = Legend.Placement.Inside;
            legend.YOffset = 8;

            plotSurface.Legend = legend;
            plotSurface.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top.
            plotSurface.XAxis1.LabelOffset = 0;
            plotSurface.YAxis1.LabelOffset = 0;
            plotSurface.Refresh();
        }
        public void PlotMarkers()
        {
            string lines = "Markers Example. Demonstrates -  * PointPlot and the available marker types * Legends, and how to place them.";
            infoBox.Text = lines;
            plotSurface.Clear();

            double[] y = new double[1] {1.0f};
            foreach (String i in Marker.getTypes())
            {
                Marker m = new Marker( (Marker.MarkerType)Enum.Parse(typeof(Marker.MarkerType), i,true), 8 );
                double[] x = new double[1];
                x[0] = (double) m.Type;
                PointPlot pp = new PointPlot();
                pp.OrdinateData = y;
                pp.AbscissaData = x;
                pp.Marker = m;
                pp.Label = m.Type.ToString();
                plotSurface.Add( pp );
            }
            plotSurface.Title = "Markers";
            plotSurface.YAxis1.Label = "Index";
            plotSurface.XAxis1.Label = "Marker";
            plotSurface.YAxis1.WorldMin = 0.0f;
            plotSurface.YAxis1.WorldMax = 2.0f;
            plotSurface.XAxis1.WorldMin -= 1.0f;
            plotSurface.XAxis1.WorldMax += 1.0f;

            Legend legend = new Legend();
            legend.AttachTo( PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right );
            legend.VerticalEdgePlacement = Legend.Placement.Outside;
            legend.HorizontalEdgePlacement = Legend.Placement.Inside;
            legend.XOffset = 5; // note that these numbers can be negative.
            legend.YOffset = 0;
            plotSurface.Legend = legend;
            plotSurface.XAxis1.LabelOffset = 0;
            plotSurface.YAxis1.LabelOffset = 0;
            plotSurface.Refresh();
        }
Пример #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="marker">The marker to place on the chart.</param>
 /// <param name="x">The world x position of the marker</param>
 /// <param name="y">The world y position of the marker</param>
 public MarkerItem( Marker marker, double x, double y )
 {
     marker_ = marker;
     x_ = x;
     y_ = y;
 }
Пример #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="marker">The marker to place on the chart.</param>
 /// <param name="point">The world position of the marker</param>
 public MarkerItem( Marker marker, PointD point )
 {
     marker_ = marker;
     x_ = point.X;
     y_ = point.Y;
 }
Пример #6
0
 /// <summary>
 /// Default constructor - a square black marker.
 /// </summary>
 /// <param name="x">The world x position of the marker</param>
 /// <param name="y">The world y position of the marker</param>
 public MarkerItem( double x, double y )
 {
     marker_ = new Marker( Marker.MarkerType.Square );
     x_ = x;
     y_ = y;
 }
Пример #7
0
 /// <summary>
 /// Constructs a square marker at the (world) point point.
 /// </summary>
 /// <param name="point">the world position at which to place the marker</param>
 public MarkerItem( PointD point )
 {
     marker_ = new Marker( Marker.MarkerType.Square );
     x_ = point.X;
     y_ = point.Y;
 }
Пример #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="marker">The marker type to use for this plot.</param>
 public LabelPointPlot( Marker marker )
     : base(marker)
 {
 }
Пример #9
0
 /// <summary>
 /// Constructor for the marker plot.
 /// </summary>
 /// <param name="marker">The marker to use.</param>
 public PointPlot( Marker marker )
 {
     marker_ = marker;
 }
Пример #10
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public PointPlot()
 {
     marker_ = new Marker();
 }