HTML onmessage function

Hi, I want to pass a value from window to HTML iframe, I have been trying the onmessage function for a while but still do not know how to use it.

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses'],
          ['2004',  1000,      400],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540]
        ]);

        var options = {
          title: 'Company Performance',
          curveType: 'function',
          legend: { position: 'bottom' }
        };
    window.onmessage = (event) => 
    {  
        if (event.data) {  
            let receivedData = event.data;     
        }   
    };
        var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="curve_chart" style="width: 900px; height: 500px"></div>
  </body>
</html>

This is a line chart, I am trying to pass data to the chart from my window, how can “receivedData” be inserted into the chart?

Have a look at the already built tutorial from Wix here which you can view in your editor.
https://www.wix.com/corvid/example/create-a-custom-chart

To pass data to and from the page to a html component then you need to use html component and onMessage and postMessage as you have already done it seems.
https://support.wix.com/en/article/corvid-working-with-the-html-element
https://www.wix.com/corvid/reference/$w.HtmlComponent.html

However, please note that if the html code you have got is through Google and not Wix, then you are better off going through Google for more help as Wix does not provide support for code that comes from third party providers.
https://developers.google.com/chart/interactive/docs/basic_load_libs