Testing CGraphic - questions and suggestions - page 8

 
Vladimir Karputov:

And immediately a wish: I can make a slanted (angled) font for both axes at once (my_graphic.FontSet("Arial",10,0,180);). Can't we make this font (or angle) setting method for a separate axis?

Afternoon! To change the axis font slope you would need to add three new fields and six new methods to the CAxis class to maintain them, and it already looks a bit overloaded at the moment. So I can't say whether such functionality will be added or not. In your case, I can advise to implement CGraphics descendant and override CreateAxes method in it (rewrite literally two lines).

 

Could you please tell me how to add text to a scientific chart? No matter how I tried, it didn't work. Here's the slightly modified code from the example:

void OnStart()
  {
   CGraphic graphic;
   graphic.Create(0,"Graphic",0,30,30,780,380);
   double x[]={-10,-4,-1,2,3,4,5,6,7,8};
   double y[]={-5,4,-10,23,17,18,-9,13,17,4};
   CCurve *curve=graphic.CurveAdd(x,y,CURVE_LINES);
   curve.Name("Example");
   graphic.XAxis().Name("X - axis");
   graphic.XAxis().NameSize(12);
   graphic.YAxis().Name("Y - axis");
   graphic.YAxis().NameSize(12);
   graphic.YAxis().ValuesWidth(15);
//--- текст
   int txt_x=2;
   int txt_y=4;
   graphic.FontSet("Arial",10);
   graphic.TextAdd(txt_x,txt_y,"Testing",ColorToARGB(clrGreen));
//--- перерисовка
   graphic.CurvePlotAll();
   graphic.Update();
   DebugBreak();
  }


In general, thank you very much that there are "numerous" examples onCGraphic!!!

You have to spend a lot of time on some small things, until you spit and swear and throw it all to hell...

 
Dennis Kirichenko:

Actually, thank you very much for the "numerous" examples on CGraphic!!!

But there are examples, for example https://www.mql5.com/ru/articles/2866 and https://www.mql5.com/ru/docs/standardlibrary/mathematics/stat
Визуализируй это! Графическая библиотека в MQL5 как аналог plot из R
Визуализируй это! Графическая библиотека в MQL5 как аналог plot из R
  • 2017.02.07
  • MetaQuotes Software Corp.
  • www.mql5.com
При исследовании и изучении закономерностей важную роль играет визуальное отображение с помощью графиков. В популярных среди научного сообщества языках программирования, таких как R и Python, для визуализации предназначена специальная функция plot. С её помощью можно рисовать линии, точечные распределения и гистограммы для наглядного представления закономерностей. В MQL5 вы можете делать всё то же самое с помощью класса CGraphics.
 
Rashid Umarov:
But there are examples, e.g. https://www.mql5.com/ru/articles/2866 and https://www.mql5.com/ru/docs/stand ardlibrary/mathematics/stat

Few. And I didn't find TextAdd() or LineAdd() there.

 
Dennis Kirichenko:

Few. And I didn't find either TextAdd() or LineAdd() there.

Good afternoon! The solution to your problem lies in these lines:

Among additional capabilities of the Graphics library we should also mention methods that allow you to add new elements to the chart:

  1. TextAdd()- adds text to an arbitrary place on the chart, the coordinates must be set to real scale. Use FontSet method to fine-tune the displayed text.
  2. LineAdd() - adds a line to an arbitrary place on the chart, the coordinates must be set to real scale.
  3. MarksToAxisAdd() - adds new marks on the specified coordinate axis.
It is important to note that the data on adding these elements is not stored anywhere, therefore, after drawing a new curve on the chart or redrawing it, they will all be overwritten.

You call the graphic.CurvePlotAll() method to overwrite the text you wanted to draw. The correct way to do this is as follows:

void OnStart()
  {
   CGraphic graphic;
   graphic.Create(0,"Graphic",0,30,30,780,380);
   double x[]={-10,-4,-1,2,3,4,5,6,7,8};
   double y[]={-5,4,-10,23,17,18,-9,13,17,4};
   CCurve *curve=graphic.CurveAdd(x,y,CURVE_LINES);
   curve.Name("Example");
   graphic.XAxis().Name("X - axis");
   graphic.XAxis().NameSize(12);
   graphic.YAxis().Name("Y - axis");
   graphic.YAxis().NameSize(12);
   graphic.YAxis().ValuesWidth(15);
//--- текст
   int txt_x=2;
   int txt_y=4;
//--- перерисовка
   graphic.CurvePlotAll();
   graphic.FontSet("Arial",10);
   graphic.TextAdd(txt_x,txt_y,"Testing",ColorToARGB(clrGreen));
   graphic.Update();
   DebugBreak();
  }

Result:

 

Roman Konopelko, thank you very much!

Yes, I think such peculiarities of work with graphics should be specified in the Documentation.

 

The question for connoisseurs is this. There is a tick chart based on a scientific CGraphic.


It needs:

1) indent as on the graph in MT. So that the last values are not adjacent to the right border of the graph;

2) Display the Y-scale on the right instead of the left.

I couldn't find such features in the methods...

 

Dennis Kirichenko:

The following is needed:

1) Indent as in the MT graph. So that the last values are not adjacent to the right border of the graph;

//+------------------------------------------------------------------+
//| Class CAxis                                                      |
//| Usage: class for create axes on a two-dimensional graphics       |
//+------------------------------------------------------------------+
class CAxis
  {
private:
...
   double            m_min_grace;      // "grace" value applied to the minimum data range
   double            m_max_grace;      // "grace" value applied to the maximum data range

public:
                     CAxis(void);
                    ~CAxis(void);
...
   double            MaxGrace(void)                     const { return(m_max_grace);      }
   void              MaxGrace(const double value)             { m_max_grace=value;        }
...
  };

//---

An example of what this looks like:



 

Dennis Kirichenko:

Need:

...

2) Display the Y scale on the right instead of the left.

There is no such option. It would be nice if it were possible not only to place the scale on the right, but also to display two independent scales (main and auxiliary), as you can do, for example, in Excel:


 

Anatoly, thank you very much! It helped in point 1. Yes, I missed theCAxis::MaxGrace(const double value) axis method.

Reason: