小编Imo*_*Imo的帖子

如何设置服务以传递谷歌工作表ID?AngularJS

我正在构建一个使用angular的小部件,它使用用户给出的Google工作表ID并以漂亮的json格式发布输出.问题是我的代码什么也没做.控制台中没有错误,当我添加ID时没有任何反应

我猜问题出在service.js中

angular.module('adf.widget.charts')
.service('chartService', function(){
  return {
     getUrl: function(key){
     var googleSheetkey = key
     }
   }
   return googleSheetkey
  });
Run Code Online (Sandbox Code Playgroud)

edit.html(添加工作表ID)

<form role="form">
  <div class="form-group">
    <label for="sample">Sample</label>
    <input type="text" class="form-control" id="sample" ng-model="config.googleSheetkey" placeholder="Enter path">
  </div>
</form>
Run Code Online (Sandbox Code Playgroud)

App.js

angular.module('adf.widget.charts', ['adf.provider', 'nvd3'])
  .config(function(dashboardProvider){
    var widget = {
      templateUrl: '{widgetsPath}/charts/src/view.html',
      reload: true,
      resolve: {
        /* @ngInject */
        urls: function(chartService, config){
          if (config.key){
            return chartService.getUrl(config.googleSheetkey);
          }
        }
      },
      edit: {
        templateUrl: '{widgetsPath}/charts/src/edit.html'
      }
  };

  dashboardProvider
      .widget('piechart', angular.extend({
        title: 'Custom Piechart',
        description: 'Creates custom Piechart with …
Run Code Online (Sandbox Code Playgroud)

javascript google-sheets angularjs tabletop.js

7
推荐指数
1
解决办法
315
查看次数

如何用css旋转SVG文本

我正在使用c3.js来生成图表.问题是我无法改变xgrid上文本元素的位置.我希望他们是横向的.但是,当我尝试使用旋转时,元素会超出svg.我怎样才能准确放置它们的位置,但要将它们放在水平位置

js小提琴:http://jsfiddle.net/yrzxj3x2/7/

这是我试过的完整代码的CSS,请参阅js小提琴

.xLineLable text{
  font-size: 12px;
}
.c3-grid text {
    fill: #000;
    transform: rotate(0);
  }
Run Code Online (Sandbox Code Playgroud)

javascript css svg c3.js

7
推荐指数
1
解决办法
2148
查看次数

PubNub EON图表不呈现数据

我正在尝试使用PUBNUB EON图表库渲染样条图.我不明白这里出了什么问题.我可以在控制台中看到数据,但图表没有渲染,只有x和y轴线.我从python SDK获取数据并通过javascript SDK订阅.控制台中没有错误消息.

我的python代码是

def counterVolume(data):
  for each in data:
    y = each.counter_volume
    data_clean = json.dumps(y, indent=4, separators=(',', ': '))
    print pubnub.publish(channel='channel', message= data_clean)


counterVolume(data)
Run Code Online (Sandbox Code Playgroud)

我的订阅javascript函数是

       var data;
       var pubnub = PUBNUB.init({
                                publish_key: 'pub',
                                subscribe_key: 'subf'
                                            });

       var channel = "c3-spline";
                    eon.chart({
                             history: true,
                            channel: 'channel',
                             flow: true,
                               generate: {
                                bindto: '#chart',
                                data: {
                                x: 'x',
                                labels: false
                                        },
                               axis : {
                                  x : {
                                  type : 'timeseries',
                                  tick: {
                                 format: '%m-%d %H:%M:%S'
                                        }
    }
    } }}); …
Run Code Online (Sandbox Code Playgroud)

javascript python charts pubnub

5
推荐指数
1
解决办法
802
查看次数

catch javascript的意外令牌错误

我正在试图找到这段代码中的错误.我已经多次检查过,有人可以指出问题所在吗?

$(function() {
  try {
    function endswith(str, ends) {
      if (ends === '') return true;
      if (str == null || ends == null) return false;
      str = String(str);
      ends = String(ends);
      return str.length >= ends.length && str.slice(str.length - ends.length) === ends;
    }
    var referrer = new URL(document.referrer).domain;
    if (endswith(referrer, "xyz.com")) {
      $(".logo .logo-external").remove();
    } else {
      $(".logo .logo-internal").remove();
    }
  } catch () {}
});
Run Code Online (Sandbox Code Playgroud)

javascript try-catch

5
推荐指数
1
解决办法
7895
查看次数

如何在d3中的水平条形图的x轴上添加一条线

我想在我的水平条形图上添加一条类似于图像的线,在这种情况下,该线应在 x 轴上表示 270,但我收到错误无效路径属性。这是plunker代码:

 var info = [
     {name: "Walnuts",   value:206}, 
    {name: "Almonds",   value:332}

    ];

    /* Set chart dimensions */
    var width   = 960, 
        height  = 500,
        margin  = {top:10, right:10, bottom:20, left:60};

    //subtract margins
    width  = width  - margin.left - margin.right;
    height = height - margin.top  - margin.bottom;

    //sort data from highest to lowest
    info = info.sort(function(a, b){ return b.value - a.value; });

    //Sets the y scale from 0 to the maximum data element


    var max_n = 0; …
Run Code Online (Sandbox Code Playgroud)

javascript d3.js

5
推荐指数
1
解决办法
2449
查看次数

查找具有多次匹配属性的JSON对象

我需要找到具有相同名称属性的json数组中的每个元素,例如此处Alaska是两次,然后我需要比较两个对象的lastupdate并选择具有最新更新时间的对象.从stackoverflow中的答案中采用(抱歉,我丢失了链接)我可以删除具有相同名称属性的对象但是如何保留具有最新更新时间的对象?

[{
    "name": "Alaska",
    "Republican_fre": 3,
    "Democrats_fre": 0,
    "winner": "R",
    "iso_2": "AK",
    "electoral_vote": 3,
    "totalComponents": 3,
    "date": "29.06.2016",
    "lastupdate": "1467233426"
}, {
    "name": "Alabama",
    "Republican_fre": 3,
    "Democrats_fre": 0,
    "winner": "R",
    "iso_2": "AL",
    "electoral_vote": 9,
    "totalComponents": 3,
    "date": "29.06.2016",
    "lastupdate": "1467233426"
}, {
    "name": "Arkansas",
    "Republican_fre": 2,
    "Democrats_fre": 0,
    "winner": "R",
    "iso_2": "AR",
    "electoral_vote": 6,
    "totalComponents": 2,
    "date": "29.06.2016",
    "lastupdate": "1467233426"
},
{
    "name": "Alaska",
    "Republican_fre": 5,
    "Democrats_fre": 0,
    "winner": "R",
    "iso_2": "AK",
    "electoral_vote": 3,
    "totalComponents": 5,
    "date": "29.06.2016",
    "lastupdate": "1467282133" …
Run Code Online (Sandbox Code Playgroud)

javascript json underscore.js angularjs

5
推荐指数
1
解决办法
144
查看次数

publish()至少需要3个参数(给出3个参数)

我正在使用ceilometer python API并将数据发布到pubnub.不确定这个错误是什么意思.

这是导致我认为的问题的代码的一部分,

def init_Data(data, channel):
  cpu_sample = cclient.samples.list(meter_name ='cpu_util')
  for each in cpu_sample:
    timetamp = each.timestamp
    volume =  each.counter_volume
    volume_int = int(volume)
    data_volume ={'value': volume_int}
    data=json.dumps(data_volume)
    print (data)


pubnub.publish(channel='orbit_channel', callback= init_Datar)
Run Code Online (Sandbox Code Playgroud)

python function ceilometer

3
推荐指数
1
解决办法
7637
查看次数

如何使用 javascript 从每个 JSON 对象中提取特定属性

我有一个 JSON 数据集

[{"key":"Albania",
    "values":[{                                                                  
        "Country_Names":"Albania",
        "Total":"3.8",
        "Change_total":"-38.7",
        "Main activity electricity and heat production":"0.1",
        "Main activity electricity plants":"","Main activity CHP plants":"",
        "Unallocated autoproducers / Other energy industry own use":"0.1",
        "Other":"1.4",
        "Manufacturing industries and construction":"1",
        "Iron and steel":"0","Chemical and petrochemical":"0","Machinery":"",
        "Mining and quarrying":"",
        "Food and tobacco":"0.1",
        "Paper, pulp and printing":"",
        "Construction":"0",
        "Transport":"2.2",
        "Road":"2.2",
        "Domestic aviation":"",
        "Rail":"0",
        "Domestic navigation":"0.1",
        "Residential":"0.2",
        "Commercial and public services":"0",
        "Agriculture/forestry":"0.2",
        "Sub-bituminous coal / Lignite":"",
        "Other bituminous coal":"",
        "Natural gas":"0",
        "Motor gasoline excl. bio":"0.3",
        "Gas/diesel oil excl. bio":"2.2" …
Run Code Online (Sandbox Code Playgroud)

javascript arrays jquery json

3
推荐指数
1
解决办法
7089
查看次数

如何使用c3.js没有数据选项

我试图使用c3.js没有数据选项但不知何故它对我不起作用.

我的小提琴:http: //jsfiddle.net/ymqef2ut/7/

我试图根据c3文档使用空选项:

 empty: { label: { text: "No Data Available" }   }
Run Code Online (Sandbox Code Playgroud)

d3.js c3.js

3
推荐指数
1
解决办法
4841
查看次数

如何将文本附加到d3.js中的一行

我试图将文本附加到条形图上创建的线条.问题是我可以看到文本元素已创建.但它没有显示在svg上的任何地方.我附加文字的代码的一部分

 var line = svg.append("line")
              .attr("x1", function(){ return x(lineEnd)})
              .attr("x2", function(){ return x(lineEnd)})
              .attr("y1", 0)
              .attr("y2", height)
              .attr("stroke-width", 6)
              .attr("stroke", "black")
              .attr("stroke-dasharray", "8,8")



  line.append('text')
             .attr('class', 'barsEndlineText')
             .attr('text-anchor', 'middle')
              .attr("x", 0)
             .attr("y", ".35em")
             .text('I am label')
Run Code Online (Sandbox Code Playgroud)

请参阅plunker获取完整代码

javascript svg d3.js

3
推荐指数
2
解决办法
1万
查看次数