如何为此标签设置值

时间:2017-06-18 06:15:59

标签: javascript jquery

我有一个用于制作图表的.js文件

  //-----------------------
  //- MONTHLY SALES CHART -
  //-----------------------
  var labels1 = '';
  $.post("pages/ajax/get_monthinfo.php", {id:1}, function(data){

        var labels1 = data;

  });

  // Get context with jQuery - using jQuery's .get() method.
  var salesChartCanvas = $("#salesChart").get(0).getContext("2d");
  // This will get the first returned node in the jQuery collection.
  var salesChart = new Chart(salesChartCanvas);    
  var salesChartData = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],   
    datasets: [
      {
        label: "Software",
        fillColor: "rgb(210, 214, 222)",
        strokeColor: "rgb(210, 214, 222)",
        pointColor: "rgb(210, 214, 222)",
        pointStrokeColor: "#c1c7d1",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgb(220,220,220)",
        data: [65, 59, 80, 81, 56, 55, 40]
      },
      {
        label: "Digital Goods",
        fillColor: "rgba(60,141,188,0.9)",
        strokeColor: "rgba(60,141,188,0.8)",
        pointColor: "#3b8bba",
        pointStrokeColor: "rgba(60,141,188,1)",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(60,141,188,1)",
        data: [28, 48, 40, 19, 86, 27, 90]
      }
    ]
  };

我有以下get_monthinfo.php脚本来获取月份列表

$latest_month = date("m");          
            $first_month = date("m")-6;         
            //getMonthName2($first_month);

            if($first_month<=0){

                $first_year = date("Y")-1;
                $fmonth = getMonthName2($first_month);  
            }else{
                $first_year = date("Y");
                $fmonth = getMonthName($first_month);   
            }

            $month_array = '';
            for($i=$first_month; $i<=$latest_month; $i++){

                if($i<=0){                  
                    $mval = getMonthName2($i);
                }else{
                    $mval = getMonthName($i);
                }

                if($month_array == '')
                    $month_array .=  $mval;
                else
                    $month_array .=  ','.$mval; 
            }
print $month_array;

此Month_array返回“1月”,“2月”,“3月”,“4月”,“5月”,“6月”,“7月”等值。

现在我的问题是如何将此值用于标签?

我的意思是下面的.js文件 -

labels: ["January", "February", "March", "April", "May", "June", "July"]

0 个答案:

没有答案