Пример #1
0
        public void plot_nplot(out NPlot.Gtk.PlotSurface2D graph)
        {
            DateTime dt             = DateTime.Now;
            int      __width_factor = 45;
            int      __graph_width  = _c_device_logfile_entries.Count * __width_factor;

            NPlot.Gtk.PlotSurface2D _graph = new NPlot.Gtk.PlotSurface2D();

            _graph.SetSizeRequest(__graph_width, 500);

            _graph.ModifyBg(StateType.Normal, cutil.get_light_grey());

            Bitmap _graphBitmap = new Bitmap(1000, 500);

            DateTimeAxis x = new DateTimeAxis();
            LinearAxis   y = new LinearAxis(-50, 0);

            x.SmallTickSize = 10;
            x.LargeTickStep = new TimeSpan(0, 30, 0);
            x.NumberFormat  = "hh:mm";


            _graph.PlotBackImage         = _graphBitmap;
            _graph.YAxis1                = y;
            _graph.XAxis1                = x;
            _graph.XAxis1.Label          = _XAxisLabel;
            _graph.XAxis1.AutoScaleTicks = false;


            _graph.YAxis1.Label = _YAxisLabel;

            _linePlot.AbscissaData = _ar_x_axis_data;
            _linePlot.OrdinateData = _ar_y_axis_data;
            _linePlot.Label        = _title;
            _linePlot.ShowInLegend = true;
            _linePlot.Pen.Width    = 2.5f;
            _linePlot.Color        = Color.Orange;

            _linePlotLegend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Top, NPlot.PlotSurface2D.YAxisPosition.Left);
            _linePlotLegend.VerticalEdgePlacement   = NPlot.Legend.Placement.Inside;
            _linePlotLegend.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside;
            _linePlotLegend.BorderStyle             = LegendBase.BorderType.Shadow;
            _linePlotLegend.YOffset = -10;
            _linePlotLegend.XOffset = -5;

            _graph.Legend        = _linePlotLegend;
            _graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            NPlot.Grid grid = new Grid();
            grid.HorizontalGridType = Grid.GridType.Fine;
            grid.VerticalGridType   = Grid.GridType.Fine;

            _graph.Add(grid, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
            _graph.Add(_linePlot);

            _graph.QueueDraw();

            graph = _graph;
        }
Пример #2
0
        public void plot_nplot(out NPlot.Gtk.PlotSurface2D graph )
        {
            DateTime dt = DateTime.Now;
            int __width_factor = 45;
            int __graph_width = _c_device_logfile_entries.Count * __width_factor;

            NPlot.Gtk.PlotSurface2D _graph = new NPlot.Gtk.PlotSurface2D ();

            _graph.SetSizeRequest ( __graph_width, 500);

            _graph.ModifyBg (StateType.Normal, cutil.get_light_grey());

            Bitmap _graphBitmap = new Bitmap (1000, 500);

            DateTimeAxis x = new DateTimeAxis ();
            LinearAxis y = new LinearAxis (-50, 0);

            x.SmallTickSize = 10;
            x.LargeTickStep = new TimeSpan (0, 30, 0);
            x.NumberFormat = "hh:mm";

            _graph.PlotBackImage = _graphBitmap;
            _graph.YAxis1 = y;
            _graph.XAxis1 = x;
            _graph.XAxis1.Label = _XAxisLabel;
            _graph.XAxis1.AutoScaleTicks = false;

            _graph.YAxis1.Label = _YAxisLabel;

            _linePlot.AbscissaData = _ar_x_axis_data;
            _linePlot.OrdinateData = _ar_y_axis_data;
            _linePlot.Label = _title;
            _linePlot.ShowInLegend = true;
            _linePlot.Pen.Width = 2.5f;
            _linePlot.Color = Color.Orange;

            _linePlotLegend.AttachTo ( NPlot.PlotSurface2D.XAxisPosition.Top, NPlot.PlotSurface2D.YAxisPosition.Left);
            _linePlotLegend.VerticalEdgePlacement = NPlot.Legend.Placement.Inside;
            _linePlotLegend.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside;
            _linePlotLegend.BorderStyle = LegendBase.BorderType.Shadow;
            _linePlotLegend.YOffset = -10;
            _linePlotLegend.XOffset = -5;

            _graph.Legend = _linePlotLegend;
            _graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            NPlot.Grid grid = new Grid ();
            grid.HorizontalGridType = Grid.GridType.Fine;
            grid.VerticalGridType = Grid.GridType.Fine;

            _graph.Add (grid, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
            _graph.Add (_linePlot);

            _graph.QueueDraw ();

            graph = _graph;
        }
Пример #3
0
	static void Main ()
	{
#if GTK
		Application.Init ();

		Window w = new Window ("Test");
		w.DeleteEvent += delegate {
			Application.Quit ();
		};
		
		NPlot.Gtk.PlotSurface2D plot = new NPlot.Gtk.PlotSurface2D ();

		PlotTest (plot);
		
		plot.Show ();
		w.Add (plot);
		w.ShowAll ();

		Application.Run ();
#else

		NPlot.PlotSurface2D s = new NPlot.PlotSurface2D ();
		Bitmap b = new Bitmap (1000, 1000);
		Graphics g = Graphics.FromImage (b);
		g.FillRectangle  (Brushes.White, 0, 0, 1000, 1000);
		Rectangle bounds = new Rectangle (0, 0, 1000, 1000);
		PlotTest (s);
		s.Draw (g, bounds);
		b.Save ("file.png", ImageFormat.Png);
#endif
	}
Пример #4
0
    private void test(Fixed _fixed)
    {
        double[] a = {0, 200, 140, 14, 240, 320, 150, 80, 170, 90};
        //Теперь можно нарисовать соответствующую линию и задать ей название в легенде
        LinePlot lp = new LinePlot();
        lp.DataSource = a;
        lp.Label = "My Label";
        //По умолчанию линия черная и тонкая. Это можно изменить предварительно созданным объектом System.Drawing.Pen
        lp.Pen = new Pen(new SolidBrush(System.Drawing.Color.Black));

        //Для лучшего вида на график наносится сетка
        Grid myGrid = new Grid();
        //По неясной причине, Vertical обозначает горизонтальные линии, которые будут видимы в данном случае
        myGrid.VerticalGridType = Grid.GridType.Fine;
        //а Horizontal — вертикальные линии сетки, которые будут убраны
        myGrid.HorizontalGridType = Grid.GridType.None;

        NPlot.Gtk.PlotSurface2D plot = new NPlot.Gtk.PlotSurface2D();
        //И очистить его от лишнего содержимого, если имеется
        plot.Clear();
        //Можно установить заголовок
        plot.Title = "Title";
        //Добавить рамочку с легендой графика
        plot.Legend = new Legend();
        //переместить ее вправо-вниз
        plot.Legend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Right);
        //отодвинуть от оси, чтобы не перекрывать числа
        plot.Legend.YOffset = 16;
        //и вынести за плоскость графика
        plot.Legend.HorizontalEdgePlacement = Legend.Placement.Outside;
        plot.Legend.VerticalEdgePlacement = Legend.Placement.Inside;
        //Расширим пространство вокруг плоскости графика
        plot.Padding = 40;
        //Чтобы линии выглядели не так убого, стоит их сгладить
        plot.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        //Осталось добавить все элементы на график
        plot.Add(myGrid);
        plot.Add(lp);
        //Если график финансовый, то надо это четко обозначить, подписав ось
        plot.YAxis1.Label = "Money";
        //и сделав нормальное отображение чисел на оси (по умолчанию — экспоненциальный вид)
        plot.YAxis1.NumberFormat = "{0:n}";
        //Последний шаг
        plot.Refresh();
        plot.Show();
        _fixed.Put(plot, 0, 120);
    }