Get rows from a table and add rows to google charts
Is the javascript part of the same file as the PHP?  If so, you should show them together as a single file, not as separate pieces of code.



Typically, you should have already made a call to the DB to get records before you ever begin rendering things to the browser like you are doing for your javascript.  Keep these pieces of logic separated.  Your page might look more like:

&lt;?php
// not-shown: file bootstrapping logic, if any
$rows = [];
// not shown: your DB logic to retrieve records

if(empty($rows)) {
    // you have no results to work with so perhaps handle this as error condition and exit/redirect.
}
?&gt;
&lt;script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
    // use json_encode to pass data from PHP to javascript literal
    var rows = &lt;?php echo json_encode($rows); ?&gt;;

    //Google Stuff
    google.charts.load('current', {packages: ['corechart']});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {
        // Define the chart to be drawn.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Element');
        data.addColumn('number', 'Percentage');
        data.addRows(rows);         

        // Set chart options
        var options = {
            title:'Sales',
            titleTextStyle: {color: 'white', bold: true},
            height:300,
            backgroundColor: '#3a3939',
            color: '#fff',
            legend: {textStyle: {color: 'white'}},
            hAxis: {gridlines: {color: 'black'}}
        };

        // Instantiate and draw the chart.
        var chart = new google.visualization.PieChart(document.getElementById('SalesChar'));
        chart.draw(data, options );
    }
&lt;/script&gt;




Note my use of json_encode() to serialize the PHP data structure into javascript in the code above. This is the #1 most useful way to interchange data between PHP and javascript. Embrace the power of JSON serialization to simplify data transfer. Dynamically building javascript data structures via PHP string concatenation is a really bad approach.



I would encourage to look at working with mysqli in an object-oriented manner.  There are a lot of legacy procedural PHP code examples out there, and while it is good to understand procedural style, I would venture to guess that you will likely fall into good development habits more easily if you bias yourself towards object-oriented programming for PHP.



Your SQL has some problems:


Don't use SELECT *. It is lazy and a potential point for application fragility.  Why make a developer go look at a database table in order to understand what fields are available to a particular section of code?  Why waste extra bandwidth sending across fields that are not needed in a certain area of code?
You have fallen into a querying-in-a-loop anti-pattern. Almost always, when you see code like this, it should be a red flag to you that perhaps a join is a better option than sending a bunch of individual queries against a database.
You may have a schema problem.  Why work with Sales/Products as a comma-separated list?  Should this be normalized into its own table (potentially with aggregation into comma-separated values if needed for purposes of a given query)?