简体   繁体   English

D3图表角度指令信息框对齐

[英]D3 Chart Angular Directive infobox alignment

I was recently assigned a task at my internship to help convert the style from an old project to an updated Verison using AngularJS. 最近,我在实习期间被分配了一项任务,以使用AngularJS帮助将样式从旧项目转换为更新的Verison。

I have this graph in the old version: 我在旧版本中有此图:

在此处输入图片说明

The graph is made in D3 on both versions, but in the new version the graph is in a custom angular directive. 两种版本均在D3中制作图形,但在新版本中,图形采用自定义的角度指令。

What I need to do is align the prices and names to the right of the bars as shown. 我需要做的是将价格和名称对准如图所示的条形右侧。

In the old code this was all one large JS file where D3 and the divs could grab the height, margins, and etc from each other easily to keep each other aligned. 在旧代码中,这只是一个大的JS文件,D3和div可以轻松地相互抓取高度,边距等,以使彼此对齐。 In this new version the directive keeps it pretty separate, I can't access divs created out side the directive. 在此新版本中,该指令将其分开,我无法访问该指令之外创建的div。 And the graph and svg elements are made using this: graph和svg元素是使用以下方法制作的:

var svg = d3.select(element[0])
                            .append('svg')
                                .attr('width', '60%')
                                .attr('id', 'chart');

Now the divs I need next to the bars are alot to complicated I think to make them this way but this is what I tried at first: 现在,我需要在酒吧旁边的div非常复杂,我想以这种方式制作它们,但这是我首先尝试的方法:

var svg = d3.select(element[0])
                                .append('div')
                                .attr('id', 'chart');

That only gives me a small div, and trying to add elements inside seem a little much. 这只给了我一个小div,尝试在其中添加元素似乎有点多。

How do I create a div with the proper information to the right of my D3 svg graph and keep it aligned with the bars inside an Angular JS custom directive? 如何在D3 svg图的右侧创建具有正确信息的div,并使其与Angular JS自定义指令中的条对齐?

Examples of someone who made a D3 angular directive with info helps, i tried looking at tooltips but they are all very simple tool tips which did not help me. 有人通过信息帮助创建了D3角度指令的示例,我尝试查看工具提示,但它们都是非常简单的工具提示,对我没有帮助。

My understanding of D3 was very limited. 我对D3的了解非常有限。 I learned that D3 can essentially only make and control SVG elements, what I ended up doing was creating a foreignObject inside the SVG and populated that foreignObject with divs and html that I wanted. 我了解到D3实际上只能制造和控制SVG元素,最终我要做的是在SVG内创建一个foreignObject,并用我想要的div和html填充该ForeignObject。

Then I was able to use good, 'ol fashion CSS to center it the way I wanted. 然后,我可以使用优质的'ol fashion CSS使其以我想要的方式居中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM