Problem after following similar example of dual y axis in google 
documantation

I copied a working example in google documentation and replaced the 
relevant code to my chart. I got an error :
Data column(s) for axis #0 cannot be of type string

HHere is the code
Here is the code: 

$items_b = get_balance_of_all_couples();
$items_c = count_trades_of_all_couples();


foreach($items_b as $key => $val_b){
 $data[$key][0] = $val_b['item'];
 
 $data[$key][1] = (float)$val_b['profit'];
}


foreach($items_c as $key => $val_c){
 $data[$key][2] = (float)$val_c['trades'];
}


 $data[0] = array('item', 'profit', 'trades');   


// website with solution


///https://blog.programster.org/php-converting-data-for-google-charts


?><html>
  <head>
    <script type="text/javascript" src=
"https://www.gstatic.com/charts/loader.js";></script>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js";></script>
    <script type="text/javascript">


 ////////       Convert PhP $data array to JavaScript array    //////////
   
   var datum = <?php echo json_encode($data); ?>;


      google.charts.load("current", {packages:['corechart']});
      google.charts.setOnLoadCallback(drawVisualization);
   


 
   
   
 ////////////////////////    Drawing the graph    //////////////////////
      function drawVisualization() {


 var data = google.visualization.arrayToDataTable([datum]);
 
 var Options = {
          title:'Profit / Loss (left) and trades count (right) of all 
traded couples',
   
          series: {
   0: {targetAxisIndex: 0},
   1: {targetAxisIndex: 1}
                   },
          
          vAxes: {
   0: {title: 'Profit', textStyle: {color: 'DodgerBlue', bold: true}},
   1: {title: 'Trades', textStyle: {color: 'Tomato', bold: true}}
                 },


   hAxis: {   title: 'Traded Couples',
   slantedText: true, 
   slantedTextAngle: 45
      },


        };
   
    var chart = new google.visualization.ColumnChart(document.getElementById
('chart_div'));
    chart.draw(data, Options);
  }//END CHART

On Saturday, May 11, 2019 at 6:21:44 PM UTC+3, Erez V. wrote:
>
> Hello,
> I created a dual y-axis
> Ireceived a chart with dual y-axis but with 2 separate x axes.
> Here is the code:
>
>  google.charts.load('current', {'packages':['corechart']});
>       google.charts.setOnLoadCallback(drawVisualization);
>    
>
>
>  
>    
>    
>  ////////////////////////    Drawing the graph    //////////////////////
>       function drawVisualization() {
>         
>         var data = new google.visualization.DataTable();
>  data.addColumn('string', 'Couple');
>  data.addColumn('number', 'profit');
>  data.addColumn('number','trades');
>  
>  for(var i = 0; i < datum_b.length; i++){
>  datum_b[i].profit=parseFloat(datum_b[i].profit);
>  datum_c[i].trades=parseFloat(datum_c[i].trades);
>  var obj_b = datum_b[i];
>  var obj_c = datum_c[i];
>  data.addRow([obj_b.item, obj_b.profit, obj_c.trades]);
>  }
>  
>      var Options = {
>          
>    series: {
>             0: {targetAxisIndex: 0},
>             1: {targetAxisIndex: 1}
>           },
>           title:'Profit / Loss (left) and trades count (right) of all 
> traded couples',
>           vAxes: {
>             
>             0: {title: 'Profit', textStyle: {color: 'DodgerBlue', bold: 
> true}},
>             1: {title: 'Trades', textStyle: {color: 'Tomato', bold: true}}
>           },
>
>
>          
>
>
>    hAxis: {title: 'Traded Couples ', direction: 1, 
>                   slantedText: true, 
>                   slantedTextAngle: 45
>       }
>    
>     
>         };
>    
>     
>
>
>     var chart = new google.visualization.ColumnChart(document.
> getElementById('chart_div'));
>     chart.draw(data, Options);
>   }//END CHART 1
>
> Here is a print screen of the result:
>
> [image: dual y.png]
>
>
> how do I change it to a single 0 x-axis
>
>
> Can I change the title of the y-axes color to the legend color?
>
>
> Thanks
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/4391f837-221c-4124-b17c-597ec8f093d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to