Testing CGraphic - questions and suggestions - page 11

 
Artyom Trishkin:

Anyway, I'm tired of explaining it to you. Those who want to, will understand.

Thanks for your patience, since this is a normal phenomenon, I will know it now and take it into account when analyzing errors in my code. But I wish they would just drop an error - it's one thing when it's impossible and another thing when, let's call it a peculiarity instead of an error, that's when the peculiarity is explained by an established tradition.

 
Aleksey Vyazmikin:


Points to this code -D.PointsFill(false);

The error was due to different size of X and Y arrays - why you couldn't write about it in the log is a mystery.

 
Aleksey Vyazmikin:

Thank you for your patience, since it is a normal phenomenon, I will know it now and take it into account when analyzing errors in my code. But I wish they would just drop an error - it is one thing when it is not possible, and another thing when, let's call it a peculiarity instead of an error, so when a peculiarity is explained by an established tradition.

Just remember one thing: the _LastError contains not only the code of the real error but codes of messages on function operation as well. In the case we're discussing, it is the code that there is no object there. And it all depends on context, when object with specific name is requested. If it's for modifying the object this code will indicate the need to understand why my object is suddenly gone and if it's for creating a new object the code saying that there is no such an object - here it's just the opposite - everything is fine and you can create it.

And take it as a rule: check the return result of the function and, if it returns a real error, then analyze the error code.

In your example, you're fooling yourselves with the fact that the creation of the canvas object was successful and you think there's an error somewhere.

 
Artyom Trishkin:

Just remember one thing: _LastError contains not only code of real error, but also codes of function messages. In this case, it is the code that there is no object. And it all depends on context, when object with specific name is requested. If it's for modifying the object this code will indicate the need to understand why my object is suddenly gone and if it's for creating a new object the code saying that there is no such an object - here it's just the opposite - everything is fine and you can create it.

And take it as a rule: you must check the return result of the function and if it returns a real error, then analyze the error code.

You're messing with your example by saying that there was a successful creation of a cantvas object and you think there's a mistake somewhere.

Ok, I will try to think in the way you have described when analyzing errors. Thank you.

Perhaps you can give an answer to my questions in this thread, which remained unanswered - about changing the size of the legend and prohibition to place information about the created curve in this legend?

 
Aleksey Vyazmikin:

OK, I'll try to think along the lines you described when analysing the errors. Thank you.

Maybe you can give an answer to my questions in this thread, which were left unanswered - about resizing the legend and not allowing information about the created curve in this legend?

I can't - it takes time. I'm sorry, I don't have time.

 
Aleksey Vyazmikin:

OK, I'll try to think along the lines you described when analysing the errors. Thank you.

  1. Reset the error code - ResetLastError()
  2. Called a function.
  3. Make sure you see what it returned.
  4. If it returned exactly an error (error code of function, see help for this particular function)
    1. You specify what exactly the error is with GetLastError()
    2. Look through your code if there mustn't be such a thing in the program or
    3. In your program logic, react to this error, if this is provided in the logic of the program (for example, erroneous stops)
    4. ...
    5. ...
    6. etc. ...
  5. If it returned a result, which is not an error, but a simple answer to a question
    1. You do what is in the logic of the program and do not look at the code of the last error, because there is only an answer to your query to the function, not a description of the error
    2. something else I can't think of...
  6. Enjoy


 
Artyom Trishkin:

I can't - it takes time. Alas, I don't have it, sorry.

Understood. I'll wait for someone who knows or has the time. But I understand that you can't do it with the library's regular tools.

 

Error inCGraphic::CreateAxes:

      //--- draw mark and set y value
      int yi_width=m_canvas.TextWidth(yvalue);
      m_canvas.TextOut(m_left-yi_width-m_mark_size-m_gap,m_yc[i]-yh/2,yvalue,ColorToARGB(clrBlack),TA_LEFT);
      if(m_mark_size>0.0)
         m_canvas.LineHorizontal(x1,x2,m_yc[i],ColorToARGB(clrBlack));
...
      //--- draw mark and set y value
      m_canvas.TextOut(m_xc[i]-xw/2,y2+m_gap,xvalue,ColorToARGB(clrBlack));
      if(m_mark_size>0.0)
         m_canvas.LineVertical(m_xc[i],y1,y2,ColorToARGB(clrBlack));

Should bem_y.Color() andm_x.Color() instead of selected, respectively.

Solved by inheriting from CGraphic and overriding CreateAxes (virtual, thank goodness).

 

The sameCGraphic::CreateAxes usesm_grid.clr_frame, which cannot be set independently:

void CGraphic::CreateAxes(void)
  {
...
//--- create frame
   m_canvas.Rectangle(m_left,m_up,m_width-m_right,m_height-m_down,m_grid.clr_frame);

A method must be added to set the value:

void              GridFrameColor(const uint clr)        { m_grid.clr_frame=clr;       }
 

Why is the horizontal line not drawn on the graph? Why does it have coordinates of int type instead of double?

//+------------------------------------------------------------------+
//|                                                   Test_CLine.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property script_show_inputs
#include <Graphics\Graphic.mqh>
#include <Graphics\Axis.mqh>

input int pix_X=800;//Ширина графика баланса
input int pix_Y=400;//Высота графика баланса
input bool Use_Koef=true;//Использовать коэфициент для установки ширины графика Parallel
input double Point_Kx=0.5;//Коэффициент ширины графика Parallel
input int Point_K=12;//Размер шрифта
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Save_Graf_P();   
  }
//+------------------------------------------------------------------+
void Save_Graf_P()
{

   int pixx_Y=pix_Y;
   int pixx_X=pix_X;

//--- отключим показ ценового графика
   ChartSetInteger(0,CHART_SHOW,false);

   long chart=0;
   string NameGraf="Test Line";

   CGraphic graphicL;

   if(ObjectFind(chart,NameGraf)<0)
   {
      graphicL.Create(chart,NameGraf,0,0,0,pixx_X,pixx_Y);//Создает графический ресурс, привязанный к объекту чарта
   }
   graphicL.Attach(chart,NameGraf);//Получить/создать  графический ресурс и привязать его к экземпляру класса CGraphic
   graphicL.BackgroundMain(NameGraf);//Получить/установить текст заголовка графика
   graphicL.BackgroundMainSize(16);//Получить/установить размер шрифта заголовка
   graphicL.HistoryNameSize(Point_K);//Устанавливает размер шрифта имени кривой
   graphicL.HistorySymbolSize(Point_K);//Получить/установить размер символов условных обозначений
   graphicL.LineAdd(-5,10,5,10,ColorToARGB(Blue,255),POINT_HORIZONTAL_DASH);//Создает и добавляет линию на график
   graphicL.CurvePlotAll();//Отрисовывает все ранее созданные кривые
   graphicL.Update();//Отображает на экране сделанные изменения
   ResetLastError();

   Sleep(3000);
   graphicL.Destroy();//Удаляет с чарта график и уничтожает графический ресурс.
   ChartSetInteger(0,CHART_SHOW,true);
}
Reason: