GRAPH horizontal resolution

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • GRAPH horizontal resolution

      I have created a GRAPH with x-size = 500.
      I attach 100 data values to the graph.
      When displayed, the graph now shows these 100 values at the right 1/5 part of the graph.
      What I want to accomplish, is that the 100 data values fills the entire graph horizontally - as if the graph could only hold 100 data values.
      Can this be achieved?
    • Hello,

      here is a little sample code. There is a graph with the radio and simple buttons attached.
      Radio button switches the drawing modes (default (100 points) / scaled (500 points)) and simple button regenerates data array.
      For drawing curve in scaled mode user draw routine is used.

      C Source Code

      1. #include "DIALOG.h"
      2. #include "stdlib.h"
      3. #include "time.h"
      4. GRAPH_Handle hGraph;
      5. GRAPH_DATA_Handle hData;
      6. GRAPH_SCALE_Handle hScale;
      7. RADIO_Handle hRadio;
      8. BUTTON_Handle hButton;
      9. // Graph data
      10. I16 aData[100];
      11. U16 i;
      12. // Generate random data array [-75; 75]
      13. void Regenerate() {
      14. for (i = 0; i < 100; i++)
      15. aData[i] = rand() % 150 - 75;
      16. }
      17. // User function for drawing scaled data to 500 points
      18. void _UserDraw(WM_HWIN hWin, int Stage) {
      19. U16 LBorder = 171; // Left border of a curve area
      20. U8 yOff = 150; // Y-offset of a curve
      21. // Replace default curve with a new curve scaled to 500 points
      22. if (Stage == GRAPH_DRAW_LAST) {
      23. // Clear background of the curve area
      24. GUI_SetColor(GUI_BLACK);
      25. GUI_FillRect(LBorder, 51, 668, 248);
      26. // Move cursor to the first point
      27. GUI_MoveTo(LBorder, yOff - aData[0]);
      28. // Curve color is also a green
      29. GUI_SetColor(GUI_GREEN);
      30. // Scale and draw data point to point
      31. for (i = 1; i < 100; i++) {
      32. GUI_DrawLineTo(LBorder + i * 5 + 2, yOff - aData[i]);
      33. }
      34. }
      35. }
      36. // Callback function for the GRAPH widget
      37. void _cbGraph(WM_MESSAGE * pMsg) {
      38. switch (pMsg->MsgId) {
      39. case WM_NOTIFY_PARENT:
      40. // If the button is released
      41. if ((pMsg->hWinSrc == hButton) && (pMsg->Data.v == WM_NOTIFICATION_RELEASED))
      42. {
      43. // Regenerate data array
      44. Regenerate();
      45. // Replace old data handler with a new data handler and attach to the graph
      46. GRAPH_DetachData(hGraph, hData);
      47. GRAPH_DATA_YT_Delete(hData);
      48. hData = GRAPH_DATA_YT_Create(GUI_GREEN, 100, aData, 100);
      49. GRAPH_DATA_YT_SetOffY(hData, 100);
      50. GRAPH_AttachData(hGraph, hData);
      51. }
      52. // If radio button changed its value
      53. if ((pMsg->hWinSrc == hRadio) && (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED))
      54. {
      55. // Set default or user drawing mode
      56. if (RADIO_GetValue(hRadio) == 1)
      57. GRAPH_SetUserDraw(hGraph, _UserDraw);
      58. else
      59. GRAPH_SetUserDraw(hGraph, NULL);
      60. }
      61. break;
      62. default:
      63. GRAPH_Callback(pMsg);
      64. break;
      65. }
      66. }
      67. void MainTask(void) {
      68. GUI_Init();
      69. WM_MULTIBUF_Enable(1);
      70. GUI_SetBkColor(GUI_LIGHTGRAY);
      71. GUI_Clear();
      72. // Generate data array for the first time
      73. srand(time(NULL));
      74. Regenerate();
      75. // Create a graph and set borders
      76. hGraph = GRAPH_CreateEx(50, 50, 720, 300, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_GRAPH0);
      77. GRAPH_SetBorder(hGraph, 170, 50, 50, 50);
      78. // Create and attach source data handler
      79. hData = GRAPH_DATA_YT_Create(GUI_GREEN, 100, aData, 100);
      80. GRAPH_DATA_YT_SetOffY(hData, 100);
      81. GRAPH_AttachData(hGraph, hData);
      82. // Create and attach a scale handler
      83. hScale = GRAPH_SCALE_Create(165, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 20);
      84. GRAPH_SCALE_SetOff(hScale, 100);
      85. GRAPH_AttachScale(hGraph, hScale);
      86. // Set callback function to the graph
      87. WM_SetCallback(hGraph, _cbGraph);
      88. // Create a radio button for switching view modes
      89. hRadio = RADIO_CreateEx(20, 130, 120, 80, hGraph, WM_CF_SHOW, 0, GUI_ID_RADIO0, 2, 30);
      90. RADIO_SetText(hRadio, "Default (100 points)", 0);
      91. RADIO_SetText(hRadio, "Rescale (500 points)", 1);
      92. // Create a button for regenerating data arrays
      93. hButton = BUTTON_CreateEx(20, 200, 80, 20, hGraph, BUTTON_CF_SHOW, 0, GUI_ID_BUTTON0);
      94. BUTTON_SetText(hButton, "Regenerate");
      95. while (1)
      96. {
      97. GUI_Delay(50);
      98. }
      99. }
      Display All

      Alex.

      The post was edited 4 times, last by LexaGB ().