0

我有一个带有 ControlWrapper 的 ComboChart,我只想在我的图表中看到小数点后两位的数字,所以我使用格式化程序,这是我的代码

 view: {

           columns: [

                     {

                //transform the numbers into strings, so the steppedArea series will work

              type: "string",

              calc: function (dt, row) {

                  var date = dt.getValue(row, 2);

                  var formatter = new google.visualization.DateFormat({pattern:"dd/MM/yyyy HH:mm"});

                  return formatter.formatValue(date);

                  console.log(calc, typeof (calc));

              }

           },

           {

             type:"string",

    calc: function (dt, row) {

          var number = dt.getValue(row, 2);

          var number = dt.getValue(row, 3);

          var number = dt.getValue(row, 4);

             var formatter = new google.visualization.NumberFormat({fractionDigits:2});

          console.log(calc);

             return formatter.formatValue(number);

             }

           },   

           6,7]

       }

但我有这个错误:

一位或多位参与者绘制失败()×

给定轴上的所有系列必须具有相同的数据类型×

你可以帮帮我吗?

4

1 回答 1

1

在Google Visualization API Discussion Group中回答过,但在这里为有类似问题的人转载:

当您应该返回一个数字值时,您正在返回一个字符串值。如果要格式化数据,可以将其作为具有“v”(值)和“f”(格式化值)属性的对象返回:

{
    type: 'number',
    calc: function (dt, row) {
        var number = dt.getValue(row, 2);
        var formatter = new google.visualization.NumberFormat({fractionDigits:2});
        return {
            v: number,
            f: formatter.formatValue(number)
        };
    }
}
于 2013-09-18T15:12:20.743 回答