小编ora*_*raz的帖子

在D3.js图形中添加点

我是D3的新手,需要创建两个数据集的图形。

在修改了我在此处找到的代码之后,我能够创建代码,并且能够使我的JSON数据正常工作,但是无法将点或笔画合并到我的版本中。

我试图以与“ lines”变量相同的方式制作一个“ dots”变量:

var dots = canvas.selectAll(".dot")
     .data(dataArray, function(d){ return line(d.values);})
    .enter()
    .append("circle")
    .attr("class", "dot")
    .attr("cx", line.x())
    .attr("cy", line.y())
    .attr("r", 3.5);
Run Code Online (Sandbox Code Playgroud)

但是在我的代码中似乎遇到了访问单个数据数组的问题。

感谢您的帮助,我的整个代码如下:

  <!DOCTYPE html>
  <html>
  <head>
  <style>
      body {
        font: 10px sans-serif;
      }

      .axis path, .axis line {
        fill: none;

        shape-rendering: crispEdges;
      }

      .line {

      }

      .area {
        fill: steelblue;
        opacity: 0.5;
      }


      .dot {
        fill: steelblue;
        stroke: steelblue;
        stroke-width: 1.5px;
      }
  </style>  
  </head>
  <body>
  <div id="disp"></div>
  <script src="https://d3js.org/d3.v3.min.js"></script>
  <script>

         var dataArray = …
Run Code Online (Sandbox Code Playgroud)

javascript d3.js

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

在构造函数中初始化静态函数指针

我试图将类成员函数指针声明为静态,因此它可以由静态成员函数调用,并将指针指向传递给构造函数的函数.

到目前为止,我还没能让它工作,这有可能吗?

#include <stdio.h>

//external callback function
static void innerFunc(int i, float f){
    printf("running inner function : %i %f\n", i, f);
}

class A{
// member function pointer
typedef void (A::*cbPtr)(int, float);
static cbPtr cbptr;

public:

//constructor
A(void(*func)(int, float))
{
   A::cbptr = func; // < this doesn't work
}

void run()
{    
   memberFunc(5, 4.4, NULL, NULL);    
} 

private:
// static member function
static void memberFunc(int i, float f, void* a, const void* aa)
{
    printf("running outer function.\n");
  //  cbptr(i, f); …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

标签 统计

c++ ×1

c++11 ×1

d3.js ×1

javascript ×1