首页 \ 问答 \ 从csv填充折线图(Populating a line graph from csv)

从csv填充折线图(Populating a line graph from csv)

我正在尝试从csv文件中提取信息并在d3中填充我的折线图。 我的代码格式大量来自: http//bl.ocks.org/mbostock/3884955

这是我从csv文件中提取信息的实际代码:

d3.csv("population.csv", function(error, data) {

    // convert your csv data and add it to dataSet
    var color = d3.scale.category10();
    color.domain(d3.keys(data[0]).filter(function(key) {return key !== "year";}));

    var census = color.domain().map(function(name) {
         return {
              name: name,
              values: data.map(function(d) {
                   return {year: d.year, population: +d[name]};  
              })
         };  
    });

我的CSV数据结构如下:

year, population1, population2, population3, population4, population5
0, 5000, 5000, 5000, 5000, 5000

(这些只是样本数字,我通过excel查看它看起来没问题)。

但是,当我通过本地主机运行它时,我收到以下错误:

Uncaught TypeError: Object function n(n){n.each(function(){var n,s=Xo.select(this),l=this.__chart__||e,f=this.__chart__=e.copy(),h=null==c?f.ticks?f.ticks.apply(f,a):f.domain():c,g=null==t?f.tickFormat?f.tickFormat.apply(f,a):bt:t,p=s.selectAll(".t...<omitted>...x'

它是由这一块看起来相对无害的代码触发的,所以我怀疑它与我首先拉动csv数据有关。

  var line = d3.svg.axis()
       //.interpolate("basis")
       .x(function(d) {return x(d.year); })
       .y(function(d) {return y(d.population); })

I'm trying to pull information from a csv file and populating my line graph in d3. I'm basing the format of my code heavily from: http://bl.ocks.org/mbostock/3884955

Here's my actual code to pull information from my csv file:

d3.csv("population.csv", function(error, data) {

    // convert your csv data and add it to dataSet
    var color = d3.scale.category10();
    color.domain(d3.keys(data[0]).filter(function(key) {return key !== "year";}));

    var census = color.domain().map(function(name) {
         return {
              name: name,
              values: data.map(function(d) {
                   return {year: d.year, population: +d[name]};  
              })
         };  
    });

My CSV data is structured like this:

year, population1, population2, population3, population4, population5
0, 5000, 5000, 5000, 5000, 5000

(these are just sample numbers, I viewed it via excel and it looks alright).

However, when I run it through the local host, I get the following error:

Uncaught TypeError: Object function n(n){n.each(function(){var n,s=Xo.select(this),l=this.__chart__||e,f=this.__chart__=e.copy(),h=null==c?f.ticks?f.ticks.apply(f,a):f.domain():c,g=null==t?f.tickFormat?f.tickFormat.apply(f,a):bt:t,p=s.selectAll(".t...<omitted>...x'

And it is triggered by this chunk of code, which looks relatively harmless, so I suspect it has to do with my pulling the csv data in the first place.

  var line = d3.svg.axis()
       //.interpolate("basis")
       .x(function(d) {return x(d.year); })
       .y(function(d) {return y(d.population); })

原文:https://stackoverflow.com/questions/22426337
更新时间:2021-07-30 16:07

最满意答案

将控制器代码更新为:

$order = $this->Order->read(null,$id);
$this->set("order",$order);

if ($this->request->is('post') || $this->request->is('put')) {
    if($this->Order->save($this->request->data)) {
       $this->Session->setFlash("Sales Agent Updated");
    }
} 

现在在reques->is('post')条件之后进行调试,该条件将显示您需要显示的内容。


Update your controller code to:

$order = $this->Order->read(null,$id);
$this->set("order",$order);

if ($this->request->is('post') || $this->request->is('put')) {
    if($this->Order->save($this->request->data)) {
       $this->Session->setFlash("Sales Agent Updated");
    }
} 

Now put a debug after the reques->is('post') condition which will show what you need to show.

相关问答

更多
  • CakePHP中仍然有PHP,因此您可以简单地使用$_POST 。 不过,坚持Cake的数据结构可能会更方便,所以要自动填充$this->data您必须像这样格式化数据: { data : { ModelName : { link : ..., ... } } } There's still PHP in CakePHP, so you can simply use $_POST. It may be more convenient to stick to Cake's data structures t ...
  • 我们可以在php.ini更改以下行: ; How many GET/POST/COOKIE input variables may be accepted max_input_vars = 1000 我们可以将它增加到3000 ,然后它就会工作。 We can change the following line in php.ini: ; How many GET/POST/COOKIE input variables may be accepted max_input_vars = 1000 We c ...
  • 只是为了咯咯笑,试试$this->params['data'] 。 我不知道为什么,但由于某种原因,它为我显示了表格数据。 文档中存在冲突的数据,您可以在此处查看http://book.cakephp.org/view/972/data 。 我猜测如果你使用FormHelper它将显示在$this->data ,如果你不使用FormHelper ,它将显示在$this->params['form'] 。 请注意,如果您使用FormHelper ,则元素的名称将为data['Model']['element_ ...
  • CakePHP并不神奇 考虑到时间线,我现在不能把表单助手放进去 做你所要求的最简单 , 最快捷的方法就是使用助手。 我想知道在不使用表单助手时是否有任何默认方式来设置表单“上下文” 没有。 为此,需要框架从模板中解析静态html,找出哪些位应该是动态的,应用一些魔术/假设,然后转储html。 CakePHP不能以这种方式工作。 使用助手 而不是静态html,使用适当的帮助方法。 例如FormHelper :: text
  • 你不能只检查帖子请求中的数据吗? $this->request->data 如果它是空的,你知道你应该返回一个新表格。 如果它不是空的,请保存它并做任何你必须做的事情。 PS - 如果您还不知道它,您可能也对此功能感兴趣: if ($this->request->is('ajax')) Can't you just check the data in the post request? $this->request->data If it's empty, you know you should re ...
  • Facebook本身并不托管这些应用程序。 它只是使用和iframe使它们出现在Facebook页面选项卡中。 应用程序本身由外部服务器托管,外部服务器也必须是您的情况。 因此,如果您计划在某处保存自定义表单数据,那么理想的解决方案是将它们保存到托管应用程序的同一服务器上。 简而言之:是的,您需要制作自己的程序来捕获发布事件。 Facebook itself does not host the applications. It just uses and iframe to make them appear ...
  • 将控制器代码更新为: $order = $this->Order->read(null,$id); $this->set("order",$order); if ($this->request->is('post') || $this->request->is('put')) { if($this->Order->save($this->request->data)) { $this->Session->setFlash("Sales Agent Updated"); } } ...
  • RedRazor的答案不是解决方案。 PHP解释器重置php标签内的引号。 这意味着您可以在解释片段中重复使用相同的引号。 这似乎更像是一个PHP Storm问题,尝试重启你的PHP Storm服务器。 我将您的代码完全复制到我的机器上并使用内置服务器中的PHP Storm。 没有修改你的代码工作。 我附上了一些我的设置图片。 此外,您必须运行PHP服务器才能获得$_POST请求,有一个图标只能在浏览器中打开,这适用于许多情况,但由于其性质,它不适用于此类请求。 以下是我的设置的一些图像: RedRazor ...
  • 这不是一个CakePHP问题。 通过使用value和name属性,您可以使无线电控制成功 。 如HTML规范中所述,无线电输入现在将成为表单数据的一部分,并将在表单提交时发送给操作。 解决方案: 1:您在服务器端的唯一解决方案是从请求对象中删除无线电输入数据(如果存在)。 2:删除名称属性并更改您的前端逻辑。 3:只发送所需的POST数据发送AJAX请求。 It's not a CakePHP issue. By using both the value and name attribute you hav ...
  • 编辑代码并连接驱动程序,如: $drivers = $_REQUEST['Driver_Name1].' '. $_REQUEST['Driver_Name2'].' '. ...; Edit your code and concatenate the drivers like: $drivers = $_REQUEST['Driver_Name1].' '. $_REQUEST['Driver_Name2'].' '. ...;

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)