使用D3.js显示图表(Displaying charts with D3.js)
我是Javascript和D3JS的新手,所以我会在这里问一下。 在开始之前, 这是支持我的特定数据集的原始示例的代码, 这是我对它的修改。
我在后端做的是使用PHP(带有一些var base)来设置JS变量名,以在同一页面上显示多个图。 这就是我的修改中每次迭代中“流”的来源。
似乎有些问题可能与我对D3.js如何具体运作缺乏了解有关,并且可能与JS有关。 我可以确认正在正确解析CSV文件,因为它显示的y范围是有效的。
例如,代码显示的图形
具有反转的y轴(具有正确的值),并且不显示x轴或标签。 此外,实际上没有绘制数据。 我怀疑它可能与错误命名的属性有关,但我不确定。 你有什么想法吗?编辑:自己修复了y轴问题。 我现在觉得很暗淡。
I'm new to Javascript and D3JS, so I'll try asking here. Before I begin, Here is the code for the original example to support my specific data set, and here is my modification of it.
What I'm doing on the back end is using PHP (with the some var base) to set JS variable names to display multiple graphs on the same page. That's where "stream" comes from in every iteration in my modifications.
There appear to be issues that are likely related to my lack of understanding of how D3.js works specifically, and possibly related to JS in general. I can confirm that the CSV file is being parsed correctly, as the y-range it displays is valid.
For example, the graph displayed by the code
has an inverted y-axis (with the correct values) andshows no x-axis or label. Furthermore, no data is actually plotted. I suspect it's likely related to the attributes being incorrectly named placed, but I am unsure. Do you have any thoughts?Edit: Fixed the y-axis issue myself. I feel quite dim right now.
原文:https://stackoverflow.com/questions/13647697
最满意答案
你正在调用
getClass()
。 这总是返回对象的引用,该对象与对象的实际执行时间类型相关联,而不是您调用它的表达式的编译时类型的类。 例如:Object foo = "this is a string"; Class<?> clazz = foo.getClass();
clazz
将引用String
的类,而不是Object
的类。您不需要查看
getClass()
的实现 - 只需查看文档 :表示此对象的运行时类的Class对象。
请注意“运行时间”位,如“在执行时确定,而不是在编译时”。
在这种情况下,我认为在
toString()
的结果中返回执行时类名是完全合理的,但如果你真的真的想要Entity
类,你可以只使用Entity.class
。You're calling
getClass()
. That always returns a reference to theClass
object associated with the actual execution-time type of the object, not the class for the compile-time type of the expression you call it on. So for example:Object foo = "this is a string"; Class<?> clazz = foo.getClass();
clazz
will refer to the class forString
, not the class forObject
.You don't need to look at the implementation of
getClass()
- just look at the documentation:The Class object that represents the runtime class of this object.
Note the "runtime" bit, as in "determined at execution time, not at compile time".
In this case I think it's entirely reasonable to return the execution-time class name within the result of
toString()
, but if you ever really really wanted theEntity
class, you could just useEntity.class
instead.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
这是它的完成: ParentClass.prototype.myMethod(); 或者如果要在当前实例的上下文中调用它,可以执行以下操作: ParentClass.prototype.myMethod.call(this) 使用参数调用父类方法的方法也相同: ParentClass.prototype.myMethod.call(this, arg1, arg2, ..) * 提示:使用apply()而不是call()将参数作为数组传递。 Here's how its done: ParentClass. ...
-
是的,但只有新式的类 。 使用super()函数: class Foo(Bar): def baz(self, arg): return super(Foo, self).baz(arg) Yes, but only with new-style classes. Use the super() function: class Foo(Bar): def baz(self, arg): return super(Foo, self).baz(arg) Fo ...
-
你正在调用getClass() 。 这总是返回对象的引用,该对象与对象的实际执行时间类型相关联,而不是您调用它的表达式的编译时类型的类。 例如: Object foo = "this is a string"; Class> clazz = foo.getClass(); clazz将引用String的类,而不是Object的类。 您不需要查看getClass()的实现 - 只需查看文档 : 表示此对象的运行时类的Class对象。 请注意“运行时间”位,如“在执行时确定,而不是在编译时”。 在这种情况 ...
-
在创建Object时,您使用的是Super类的引用,但是您的对象是子类,因此在调用m1()方法时,将调用被覆盖的方法。 如果你想调用超类的方法,那么对象应该是超类。 如下: Parent parent=new Parent(); parent.m1(); 要么 你可以从子类调用超类m1()方法。 @Override public void m1() { super.m1(); System.out.println("Child method"); } 要不然 import j ...
-
在Child类中重写calculateCost 。 因此,当从Child调用super.toString()时, super.toString()中的super.toString()将是Child的calculateCost 。 你必须在Child类中显式地放置super.calculateCost()来调用Parent的calculateCost 。 calculateCost is overriden in the Child class. Therefore when super.toString() ...
-
用来比较: getattr(className, 'methodName') is getattr(className, 'method') 如果为false ,则覆盖该方法 use to compare: getattr(className, 'methodName') is getattr(className, 'method') if false, the method was overridden
-
进一步的答案,你可以做类似的方法 class base(object): @classmethod def func(cls): print("in base: " + cls.__name__) class child(base): @classmethod def func(cls): super(cls, cls).func() print("in ...
-
子类方法不覆盖父级中相同签名的方法(Child class method not overriding the method of the same signature in parent)[2022-01-23]
看到简单的情况,它的工作原理: public class Test{ public static void main(String args[]) { new PlayerPaddle().receiveEvent(); } } abstract class Actor { public void releasedEvent(KeyEvent e) { } } abstract class Paddle extends Actor { public void mo ... -
您遇到了切片问题 。 vector
.push_back() 复制其参数,因此它调用Parent::Parent(const Parent &) (即复制构造函数) * 。 这真的没有什么不同: Parent x[10]; x[0] = Parent(); x[1] = Child(); *或者它可能是Parent::operator=(const Parent &) ,即复制赋值。 我累了,我不记得它需要什么。 You are encountering the slicing probl ...