在 d3.js 地图中添加交互性时出现问题 [下拉菜单]

发布于 2025-01-11 07:20:06 字数 2512 浏览 0 评论 0原文

我想制作地图作为定量分析的输出。 我有多个变量要添加到我的地图中,并且我不想有 n 个输出,在本例中为 n 个地图。您可以查看简化的数据框(列是年份,但也可以是一组不同的变量)简单数据框

在我看来 d3.js 是个好主意,因为它可以显示 1带有下拉菜单的地图,用户可以选择变量。

我之前用d3.js制作了一张地图,我用它作为模板。我已经让它变得安静、基本和简单(非常小的数据集等),你可以在这个 repo GitHub 中找到它: https://github.com/Mathiaslauber/Without_interactivity

这是我第一次尝试实现的 Github 存储库互动性 https://github.com/Mathiaslauber/Interactivity_first_try 或者,如果您愿意,我刚刚制作了一个 FiddleJS 来让事情变得更容易: Fiddle JS 交互性首次尝试

这是一个更大项目的一部分,如果你愿意的话你可以看看。 GithubPages

到目前为止,我已经进行了绝望的修改,但仍然不成功,因为示例通常在很多方面都非常不同,所以对我来说很难重现。我对 JavaScript 中的函数实现很陌生,而且很糟糕。 以下两个链接是看起来并不复杂并启发了我的示例:

[A] http://tietyk.github.io/D3/Prototype/part9-9.html

[B] http://bl.ocks.org/rgdonohue/6a30b731230f6e242a54

我在第196行有一堆有趣的代码下面的-226,也在js文件中。 问题是我缺少让它发挥作用的线索。

使用的第一个来自来源 [A],它基于悬停效果。 二、来自来源[B]和使用的按钮 两者都引用了 json 属性,我使用 Csv。总体格式和功能实现不同。

我可能会花一个月的时间来尝试自己解决这个问题。因此,如果您有任何提示,它将对我有很大帮助:我应该检查的内容、我的代码中缺少的内容等。

 // 2 bunch of codes that were used in order to add interactivity     

    /*        
       color();
               
       d3.selectAll("input").on("change", function() {
           attribute = this.id;
           color();
       });

       function color(){
           
           d3.selectAll('circle')
               .transition()
               .attr( "fill", function(d){
                   return (mycolor.domain())}  
                           )
       }
       
       */
    /*  
        var timeline = d3.selectAll(".time-series")
        .on("mouseover", function(d, i) {
          year = i;
          svg.selectAll("path")
            .attr("class", quantify);
          d3.selectAll(".time-series")
            .attr("class", "time-series");
          this.className = "time-series active";
        });
    */

I want to produce maps as an output for quantitative analysis.
I Have multiple variables to add to my map, and, I dont want to have n-output, in this case, n-maps. You can have a look of the simplified dataframe (colomns are years, but it could also be a set of different variables) :
Simple data frame

It seems to me d3.js was a good idea, because it can display 1 map with a dropdown menu, and the user can select the variable.

I have produced a map with d3.js before, and I use it as template. I have made it quiet basic and simple (really small dataset, etc), you can found it here in this repo GitHub :
https://github.com/Mathiaslauber/Without_interactivity

Here is the Github repo with my first try of implementing interactivity
https://github.com/Mathiaslauber/Interactivity_first_try
Or if you prefer, I have just made a FiddleJS to make things easier : Fiddle JS Interacivity first try

It was part of a bigger project, you can have a look if you want. GithubPages

So far, I have made deseperates modifications that remain unsucessful, because examples are usually very diffrent in many aspects, so hardly reproductible for me. I'm quiet new AND bad with function implemantation in JavaScript.
The two following links are examples that did not seem that complicated and inspired me :

[A] http://tietyk.github.io/D3/Prototype/part9-9.html

[B] http://bl.ocks.org/rgdonohue/6a30b731230f6e242a54

I have interesting bunch of codes at lines 196-226 below, also in the js file.
Problem is I'm missing clues to make it work.

First one used come from source [A] and it's based on an hover effect.
Second, from source [B] and used button
Both refered to json properties, and I use Csv. The overall format and function implementation is different.

I could spend like a month trying to figure this out myself. So if you have any hints, It would help me a lot : Things i should check, that are missing in my code, etc.

 // 2 bunch of codes that were used in order to add interactivity     

    /*        
       color();
               
       d3.selectAll("input").on("change", function() {
           attribute = this.id;
           color();
       });

       function color(){
           
           d3.selectAll('circle')
               .transition()
               .attr( "fill", function(d){
                   return (mycolor.domain())}  
                           )
       }
       
       */
    /*  
        var timeline = d3.selectAll(".time-series")
        .on("mouseover", function(d, i) {
          year = i;
          svg.selectAll("path")
            .attr("class", quantify);
          d3.selectAll(".time-series")
            .attr("class", "time-series");
          this.className = "time-series active";
        });
    */

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文