首页 \ 问答 \ C3.js连接失败(C3.js connection fails)

C3.js连接失败(C3.js connection fails)

我在连接到c3.js库时遇到了麻烦。 我按照c3js.org上的说明操作,但它不起作用。 我在网站上使用了一个简单的例子,但它没有显示任何东西。 我这样加载:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/c3.css">

<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="../js/c3.min.js"></script>

</head>
<body>
<div id="chart"></div>

var chart = c3.generate({
	bindto: '#chart', 
	data: {
	  columns: [
	    ['data1', 30, 50, 70, 90], 
	    ['data2', 20, 40, 60, 80]
	  ]
	}
});
</body>
</html>

问题是我看不到图表。 我只看到从我的var开始输入的代码。 谢谢大家


I'm having trouble with connecting to the c3.js library. I followed the instructions on c3js.org but it won't work. I used a simple example from the website but it isn't showing a thing. I load like this:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/c3.css">

<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="../js/c3.min.js"></script>

</head>
<body>
<div id="chart"></div>

var chart = c3.generate({
	bindto: '#chart', 
	data: {
	  columns: [
	    ['data1', 30, 50, 70, 90], 
	    ['data2', 20, 40, 60, 80]
	  ]
	}
});
</body>
</html>

the problem is i can't see a chart. I only see the code i entered starting from my var. Thank you every one


原文:https://stackoverflow.com/questions/28670392
更新时间:2022-06-08 16:06

最满意答案

你没有在孩子中调用剪切,文件描述符也搞乱了。

要执行任务,您必须关闭父项的stdout,在execvp之前在父项中执行write end stdout。 在孩子中你必须关闭孩子的 stdin并在execvp之前将你的孩子的阅读结束作为stdin。 通过这种方式, your parent's stdout is stdin of your child (创建管道b / w两个)。

int main()
{
   int filedes[2];
   int p;
   pid_t pid = 0, pid1 = 0;
   p=pipe(filedes);
   FILE *stream;
   char buff[20];
   char *args[80];

   printf("pipe command returns %d, %d ,%d\n",p, filedes[0],filedes[1]);

   if(pipe(filedes) == -1) /* Create the pipe */
      printf("error pipe");
      pid1=fork();
      pid=getpid();
      switch (pid1) { /* Create a child process */
      case -1:
         printf("error fork"); break;
      case 0: /* Child */
      /* Close unused write end */
      /* Child can now read from pipe */
         if (close(filedes[1]) == -1)
            printf("error close");
         printf("I am a child process pid %d, and will read from pipe\n",pid);

         close(0); //close stdin of child
         dup(filedes[0]); //make pipes read end stdin of child

         args[0] = "cut";
         args[1] = "-b";
         args[2] = "1";
         args[3] = NULL;
         execvp(args[0],args);
         break;

         default: /* Parent */
         /* Close unused read end */
         /* Parent can now write to pipe */
         if (close(filedes[0]) == -1)
            printf("error close");
         printf("I am the parent process pid %d, and will write to pipe\n", pid );

         close(1); //close stdout
         dup(filedes[1]); //make write end of pipe stdout of parent
         args[0] = "ls";
         args[1] = "-l";
         args[2] = NULL;
         execvp(args[0],args);
         break;
   }
}

You didn't called the cut in the child and also the file descriptors are messed up here.

For performing the task you have to close the stdout of parent and make the write end stdout in parent before execvp. In child you have to close stdin of child and make read end as stdin to your child before execvp. In that way your parent's stdout is stdin of your child(creating the pipe b/w two).

int main()
{
   int filedes[2];
   int p;
   pid_t pid = 0, pid1 = 0;
   p=pipe(filedes);
   FILE *stream;
   char buff[20];
   char *args[80];

   printf("pipe command returns %d, %d ,%d\n",p, filedes[0],filedes[1]);

   if(pipe(filedes) == -1) /* Create the pipe */
      printf("error pipe");
      pid1=fork();
      pid=getpid();
      switch (pid1) { /* Create a child process */
      case -1:
         printf("error fork"); break;
      case 0: /* Child */
      /* Close unused write end */
      /* Child can now read from pipe */
         if (close(filedes[1]) == -1)
            printf("error close");
         printf("I am a child process pid %d, and will read from pipe\n",pid);

         close(0); //close stdin of child
         dup(filedes[0]); //make pipes read end stdin of child

         args[0] = "cut";
         args[1] = "-b";
         args[2] = "1";
         args[3] = NULL;
         execvp(args[0],args);
         break;

         default: /* Parent */
         /* Close unused read end */
         /* Parent can now write to pipe */
         if (close(filedes[0]) == -1)
            printf("error close");
         printf("I am the parent process pid %d, and will write to pipe\n", pid );

         close(1); //close stdout
         dup(filedes[1]); //make write end of pipe stdout of parent
         args[0] = "ls";
         args[1] = "-l";
         args[2] = NULL;
         execvp(args[0],args);
         break;
   }
}

相关问答

更多
  • 这实质上是一个shell如果构建一个重定向链,即类似的东西 ls | grep foo | sort | uniq 在Unix编程中有一些很好的介绍性文本,其中通过本书实现了一个简单的shell。 而一个shell的任务之一就是重定向。 其中一本书是Michael K. Johnson和Erik W. Troan的“Linux Application Programming”。 该书的主页: http : //ladweb.net/ 要为N个过程构建一个重定向链,您需要N-1个管道。 对于每个重定向,使用 ...
  • 你没有在孩子中调用剪切,文件描述符也搞乱了。 要执行任务,您必须关闭父项的stdout,并在execvp之前在父项中执行write end stdout。 在孩子中你必须关闭孩子的 stdin并在execvp之前将你的孩子的阅读结束作为stdin。 通过这种方式, your parent's stdout is stdin of your child (创建管道b / w两个)。 int main() { int filedes[2]; int p; pid_t pid = 0, pid1 ...
  • 这是标准的行为。 你关闭了管道的读端,所以无处可写。 这导致SIGPIPE信号被发送到写入过程。 SIGPIPE的默认行为是终止接收信号的过程。 如果你想让你的过程在信号中生存下来,你必须忽略或忽略它。 然后,您必须检查write结果,因为当管道读取结束时,它将返回一个错误。 That's standard behavior. You close the read-end of the pipe, so there is nowhere to write. That results in a SIGPIPE ...
  • 你得到孩子PID的机会就在你分叉的时候。 蟒蛇: import os child_pid = os.fork() if child_pid == 0: print "This is the child, my pid is", os.getpid() else: print "This is the parent, my child pid is", child_pid C: pid_t child_pid = fork(); if (child_pid == 0) { prin ...
  • 我在这段代码中看到了五个错误。 我将从最不重要到最重要的列出它们。 我没有尝试修复任何错误,因此可能会有更多隐藏在这些错误背后。 你忘了包含sys/wait.h 编译器应该抱怨隐式的wait声明。 (如果您的编译器没有提出任何投诉,请打开所有警告。) 您没有检查是否有任何系统调用失败。 每次系统调用后都应检查失败。 当一个失败时,打印到stderr失败的完整描述,包括失败的系统调用的名称,所涉及的所有文件的名称(如果有的话)和strerror(errno) ,然后以非零的形式退出程序(不成功的)退出代码。 ...
  • 正如sarnold建议的那样,您需要更改通话顺序。 先读,等等。 即使您的方法有效,您也可能会错过最后一次阅读。 即,在读取写入的最后一组字节之前退出循环。 问题可能是ifstream是非阻塞的。 我从来都不喜欢iostream,即使在我的C ++项目中,我也总是喜欢C的stdio函数的简单性(即FILE *,fprintf等)。 解决这个问题的一种方法是读取描述符是否可读。 您可以使用select来确定是否有数据在该管道上等待。 如果你打算从多个孩子那里读书,你将需要选择,所以不妨现在就学习它。 至于一个 ...
  • 简答:不。 父进程可以控制其子进程的终端或进程组,这就是为什么我们有wait()和waitpid()函数的原因。 一个孩子对其父母没有那种控制权,所以没有内置的东西。 如果你真的需要一个孩子来知道它的父母什么时候退出,你可以让父母通过一个atexit()处理程序向孩子发送一个信号,让孩子捕捉到这个信号。 Short answer: no. A parent process can control the terminal or process group of its children, which is ...
  • 我认为要解决的第一个问题是,当您尝试读取/写入数据时,管道的两端都会打开。 如果您正在将数据写入管道 close(fd[READ_END]) write(...) close(fd[WRITE_END]) 其次,unix中的管道是单工的。 您似乎同时尝试从管道读取和写入。 如果你想这样做,你将不得不打开两个管道。 我修改了你的程序,向你展示如何从管道读取,然后写入父/子管道。 希望这对你有所帮助。 #include #include #include
  • switch语句基本上没问题,虽然你不需要pid变量,因为你没有对它做任何事情。 父代码也基本上没问题,但是字符串实际上是没有NUL终结符的18个字节,而是带有NUL终结符的19个字节。 在孩子中处理换行符和NUL终止符是一个好习惯,所以我会坚持使用17并从字符串中删除换行符。 子代码错了。 您需要一个变量来存储read的返回值。 您需要检查返回值以确保read成功。 您需要在字符串中添加NUL终止符。 在C编程语言中, “字符串”是以零字节结尾的字符数组(称为NUL终止符,写为'\0' )。 您的工作是确 ...
  • 当你fdopen 。 你必须fclose 。 如果您close原始文件描述符,则与FILE*关联的缓冲区中的所有尚未写入的数据都将丢失。 When you fdopen. you must fclose. If you close the original file descriptor instead, all not-yet-written data in buffers associated with the FILE* get lost.

相关文章

更多

最新问答

更多
  • 您如何使用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)