javascript数组没有重复

时间:2017-07-11 14:30:12

标签: javascript arrays repeat

这是我可以随机访问十个值的数组。

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
  </script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
 <script type="text/javascript">
// Load google charts
google.charts.load('current', {'packages':['corechart','line']});

google.charts.setOnLoadCallback(seven_day_compare);

// Draw the chart and set the chart values

function seven_day_compare() {
  var data = google.visualization.arrayToDataTable(
 [["Date","likes","share"],["2017-07-01",30,20],["2017-07-02",20,20],["2017-07-03",16,10],["2017-07-4",10,15],["2017-07-5",31,66],["2017-07-6",20,15],["2017-07-7",2,5],["2017-07-8",8,6],["2017-07-09",30,20],["2017-07-10",20,20],["2017-07-11",16,10],["2017-07-12",10,15],["2017-07-13",31,66],["2017-07-14",20,15],["2017-07-15",2,5],["2017-07-16",8,6]]    
);

  // Optional; add a title and set the width and height of the chart
  var options = {'title':'Compare like and share', 'width':550, 'height':400,'pointSize': 10,'hAxis':{
        'slantedText': true, 
          'slantedTextAngle':30},'vAxis':{}};

  // Display the chart inside the <div> element with id="differnt"

  var chart = new google.visualization.LineChart(document.getElementById('chart'));
  chart.draw(data, options);
} 
</script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id = "chart"></div>
  </body>
</html>

但是,它有时会重复相同的值。如何确保显示值不会连续重复?

0 个答案:

没有答案