pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

使用關聯數組的 D3 日歷視圖

D3 Calendar View using Associative Array(使用關聯數組的 D3 日歷視圖)
本文介紹了使用關聯數組的 D3 日歷視圖的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想創建一個日歷視圖,如下例所示:

編輯 3:

我已經解決了第 1 步和第 2 步,這里是 jsfiddle 鏈接:http://jsfiddle.net/makoto/ARy8d/9/

現在試圖找到一種解決方法來在同一個單元格中添加多值

例如,如果我在數組中有 2 個值具有相同的日期,我想添加并在右側單元格中查看它們.但是代碼現在的作用是,如果有 2 個值具有相同的日期值,則最后一個會覆蓋第一個.

任何幫助都可以,在此先感謝.

解決方案

對于那些與我曾經遇到過類似問題的人來說,這里是針對 1 號和 2 號的解決方案.希望這會有所幫助.

數組如下所示:BigWordsDates2 = {"#Tahrir":[["2012-10-12",20],["2012-10-13",1],["2012-10-19",15]],"#Egypt":[["2012-10-01",3],["2012-10-03",2],["2012-10-04",3],["2012-10-07",1],["2012-10-10",1],["2012-10-13",2],["2012-10-14",1],["2012-10-15",1],["2012-10-16",1],["2012-10-17",4],["2012-10-19",5]]};

像這樣保存你的目標數組值的值:var tahrir = BigWordsDates2['#Tahrir']

然后用它覆蓋 CSV 數據.您可以在下面的 jsfiddle 中找到帶有解決方案的示例.

http://jsfiddle.net/makoto/ARy8d/7/

I want to create a Calendar View Like this example: http://bl.ocks.org/4063318:

Actually i am trying to modify it.

I have an associative array like this: #AdminCourt[["2012-10-02", 2], ["2012-10-09", 2], ["2012-10-16", 1]] #ConstituentAssembly[["2012-10-02", 2], ["2012-10-09", 2], ["2012-10-12", 2], ["2012-10-16", 2]]

I tried filling the calendar like this:

BigWordsDates2.map(function(d) {
              return {
                 date: d[0],
                 close: d[1]
              };
              var data = d3.nest()
    .key(function(d) { return d.Date; })
    .rollup(function(d) { return (d.Close - 0); });

  rect.filter(function(d) { return d in data; })
      .attr("class", function(d) { return "day " + color(data[d]); })
    .select("title")
      .text(function(d) { return d + ": " + percent(data[d]); });
      });

I know i am not looping through the array and i dont know how i tried for each but it seems that i dont get it correctly.

Here are the stuff that i need ur help with :)

  1. Loop through the array.( I know how to loop on it but i dont know if there is a way through the D3 class )
  2. How to Make each cell clickable.
  3. if i can add MultiValues in a cell ( Probably the keys of the array it depends on the date values).
  4. How to make the calendar Dynamic Not Set to a certain Range.

Here is the script code i have:

var w = 760,
    h = 530;
    var cloudwidth = 700, cloudheight=500;
    var FunctionCount=0;
    var BigWord;
    var SmallWord;
    var tweets =  <?php echo json_encode($Row_Words_Repeated_Relation); ?>;
    //var tweets = JSON.parse(TweetsAnalized);
    var tweetscounts = JSON.parse('<?php echo $Array_OfCounters_to_json ?>');
    var BigWordsDates2 = <?php echo json_encode($Array_OfDates); ?>;
    //var BigWordsDates2 = JSON.parse(BigWordsDates);
    var OriginalTweets = JSON.parse('<?php echo mysql_real_escape_string($OriginalTweets_to_json) ?>');

    var width = 960,
    height = 136,
    cellSize = 17; // cell size

var day = d3.time.format("%w"),
    week = d3.time.format("%U"),
    percent = d3.format(".1%"),
    format = d3.time.format("%Y-%m-%d");

var color = d3.scale.quantize()
    .domain([-.05, .05])
    .range(d3.range(11).map(function(d) { return "q" + d + "-11"; }));

var svg = d3.select("body").selectAll("svg")
    .data(d3.range(2005, 2015))
  .enter().append("svg")
    .attr("width", width)
    .attr("height", height)
    .attr("class", "RdYlGn")
  .append("g")
    .attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")");

svg.append("text")
    .attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)")
    .style("text-anchor", "middle")
    .text(function(d) { return d; });

var rect = svg.selectAll(".day")
    .data(function(d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
  .enter().append("rect")
    .attr("class", "day")
    .attr("width", cellSize)
    .attr("height", cellSize)
    .attr("x", function(d) { return week(d) * cellSize; })
    .attr("y", function(d) { return day(d) * cellSize; })
    .datum(format);

rect.append("title")
    .text(function(d) { return d; });

svg.selectAll(".month")
    .data(function(d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
  .enter().append("path")
    .attr("class", "month")
    .attr("d", monthPath);

/*d3.csv("dji.csv", function(error, csv) {
  var data = d3.nest()
    .key(function(d) { return d.Date; })
    .rollup(function(d) { return (d[0].Close - d[0].Open) / d[0].Open; })
    .map(csv);

  rect.filter(function(d) { return d in data; })
      .attr("class", function(d) { return "day " + color(data[d]); })
    .select("title")
      .text(function(d) { return d + ": " + percent(data[d]); });
});*/
BigWordsDates2["#Tahrir"].map(function(d) {
              return {
                 date: d[0],
                 close: d[1]
              };
              var data = d3.nest()
    .key(function(d) { return d.Date; })
    .rollup(function(d) { return (d.Close - 0); });

  rect.filter(function(d) { return d in data; })
      .attr("class", function(d) { return "day " + color(data[d]); })
    .select("title")
      .text(function(d) { return d + ": " + percent(data[d]); });
      });




function monthPath(t0) {
  var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
      d0 = +day(t0), w0 = +week(t0),
      d1 = +day(t1), w1 = +week(t1);
  return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize
      + "H" + w0 * cellSize + "V" + 7 * cellSize
      + "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize
      + "H" + (w1 + 1) * cellSize + "V" + 0
      + "H" + (w0 + 1) * cellSize + "Z";
}

d3.select(self.frameElement).style("height", "2910px");

Thanks In Advance and i would really appreciate the help.

EDIT 1:

I tried to work on something like that:

var data1 = d3.entries(BigWordsDates2).forEach(function(d) {
for each (var i in BigWordsDates2[d.key]){
return {
       Date: BigWordsDates2[d.key][i][0],
       Close: BigWordsDates2[d.key][i][1]
    };
};
var data = d3.nest()
.key(function(data1) { return d.Date; })
.rollup(function(data1) { return (d.Close - 0); });

Edit 2: i worked around what was above a bit and this is all i can think of would really need Help, no idea why the values aint appended in the calendar.

var width = 960,
    height = 136,
    cellSize = 17; // cell size

var day = d3.time.format("%w"),
    week = d3.time.format("%U"),
    percent = d3.format(".1%"),
    format = d3.time.format("%Y-%m-%d");

var color = d3.scale.quantize()
    .domain([-.05, .05])
    .range(d3.range(11).map(function(d) { return "q" + d + "-11"; }));

var svg = d3.select("body").selectAll("svg")
    .data(d3.range(2005, 2015))
  .enter().append("svg")
    .attr("width", width)
    .attr("height", height)
    .attr("class", "RdYlGn")
  .append("g")
    .attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")");

svg.append("text")
    .attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)")
    .style("text-anchor", "middle")
    .text(function(d) { return d; });

var rect = svg.selectAll(".day")
    .data(function(d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
  .enter().append("rect")
    .attr("class", "day")
    .attr("width", cellSize)
    .attr("height", cellSize)
    .attr("x", function(d) { return week(d) * cellSize; })
    .attr("y", function(d) { return day(d) * cellSize; })
    .datum(format);

rect.append("title")
    .text(function(d) { return d; });

svg.selectAll(".month")
    .data(function(d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
  .enter().append("path")
    .attr("class", "month")
    .attr("d", monthPath);

/*d3.csv("dji.csv", function(error, csv) {
  var data = d3.nest()
    .key(function(d) { return d.Date; })
    .rollup(function(d) { return (d[0].Close - d[0].Open) / d[0].Open; })
    .map(csv);

  rect.filter(function(d) { return d in data; })
      .attr("class", function(d) { return "day " + color(data[d]); })
    .select("title")
      .text(function(d) { return d + ": " + percent(data[d]); });
});*/


    d3.entries(BigWordsDates2).map(function(d) {
        for each (var i in BigWordsDates2[d.key]){
            /*var count =i;
              return {
                 Date: i[0],
                 Close: i[1]
              };*/                                               
      rect.filter(function(i) { return i in BigWordsDates2; })
          .attr("class", function(i) { return "day " + color(i[0]); })
        .select("title")
          .text(function(i) { return d.key + ": " + percent(i[1]); });

       };
  });



function monthPath(t0) {
  var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
      d0 = +day(t0), w0 = +week(t0),
      d1 = +day(t1), w1 = +week(t1);
  return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize
      + "H" + w0 * cellSize + "V" + 7 * cellSize
      + "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize
      + "H" + (w1 + 1) * cellSize + "V" + 0
      + "H" + (w0 + 1) * cellSize + "Z";
}

d3.select(self.frameElement).style("height", "2910px");

I think am close. any help would be appreciated.

I made a jsfiddle template: http://jsfiddle.net/ARy8d/1/

EDIT 3:

i got Steps 1 and 2 are solved and here is the jsfiddle link: http://jsfiddle.net/makoto/ARy8d/9/

Now trying to find a workaround to add multivalues in same cell

For Example if i have 2 values in array that has the same date i want to add and view them in the right cell. however what the code does right now that if there are 2 values with the same date value the last one overwrites the first one.

Any help will do, thanks in advance.

解決方案

Here Is The Solution For Number 1 and 2 for those who has the problem similar to the ones i used to have. hope that will helpful.

The array Looks Like That: BigWordsDates2 = {"#Tahrir":[["2012-10-12",20],["2012-10-13",1],["2012-10-19",15]],"#Egypt":[["2012-10-01",3],["2012-10-03",2],["2012-10-04",3],["2012-10-07",1],["2012-10-10",1],["2012-10-13",2],["2012-10-14",1],["2012-10-15",1],["2012-10-16",1],["2012-10-17",4],["2012-10-19",5]]};

Save the Value that Your Targeted array Values you want like that: var tahrir = BigWordsDates2['#Tahrir']

and then overwrite the CSV Data with it. You can Find The example with solution in the jsfiddle below.

http://jsfiddle.net/makoto/ARy8d/7/

這篇關于使用關聯數組的 D3 日歷視圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 冷柜风机-冰柜电机-罩极电机-外转子风机-EC直流电机厂家-杭州金久电器有限公司 | 环氧树脂地坪_防静电地坪漆_环氧地坪漆涂料厂家-地壹涂料地坪漆 环球电气之家-中国专业电气电子产品行业服务网站! | 北京三友信电子科技有限公司-ETC高速自动栏杆机|ETC机柜|激光车辆轮廓测量仪|嵌入式车道控制器 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | 上海单片机培训|重庆曙海培训分支机构—CortexM3+uC/OS培训班,北京linux培训,Windows驱动开发培训|上海IC版图设计,西安linux培训,北京汽车电子EMC培训,ARM培训,MTK培训,Android培训 | 耐高温风管_耐高温软管_食品级软管_吸尘管_钢丝软管_卫生级软管_塑料波纹管-东莞市鑫翔宇软管有限公司 | 矿用履带式平板车|探水钻机|气动架柱式钻机|架柱式液压回转钻机|履带式钻机-启睿探水钻机厂家 | 软文发布-新闻发布推广平台-代写文章-网络广告营销-自助发稿公司媒介星 | led全彩屏-室内|学校|展厅|p3|户外|会议室|圆柱|p2.5LED显示屏-LED显示屏价格-LED互动地砖屏_蕙宇屏科技 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-北京罗伦过滤技术集团有限公司 | 都江堰招聘网-都江堰人才网 都江堰人事人才网 都江堰人才招聘网 邢台人才网_邢台招聘网_邢台123招聘【智达人才网】 | ★塑料拖链__工程拖链__电缆拖链__钢制拖链 - 【上海闵彬】 | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 金属雕花板_厂家直销_价格低-山东慧诚建筑材料有限公司 | 搪玻璃冷凝器_厂家-越宏化工设备 | uv固化机-丝印uv机-工业烤箱-五金蚀刻机-分拣输送机 - 保定市丰辉机械设备制造有限公司 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 磁力抛光研磨机_超声波清洗机厂家_去毛刺设备-中锐达数控 | 扬子叉车厂家_升降平台_电动搬运车|堆高车-扬子仓储叉车官网 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 移动厕所租赁|移动卫生间|上海移动厕所租赁-家瑞租赁 | 河南中专学校|职高|技校招生-河南中职中专网 | 聚合氯化铝厂家-聚合氯化铝铁价格-河南洁康环保科技 | 5L旋转蒸发器-20L-50L旋转蒸发器-上海越众仪器设备有限公司 | 钢板仓,大型钢板仓,钢板库,大型钢板库,粉煤灰钢板仓,螺旋钢板仓,螺旋卷板仓,骨料钢板仓 | 螺纹三通快插接头-弯通快插接头-宁波舜驰气动科技有限公司 | 3d可视化建模_三维展示_产品3d互动数字营销_三维动画制作_3D虚拟商城 【商迪3D】三维展示服务商 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 蓝莓施肥机,智能施肥机,自动施肥机,水肥一体化项目,水肥一体机厂家,小型施肥机,圣大节水,滴灌施工方案,山东圣大节水科技有限公司官网17864474793 | 三防漆–水性三防漆–水性浸渍漆–贝塔三防漆厂家 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 | 高清视频编码器,4K音视频编解码器,直播编码器,流媒体服务器,深圳海威视讯技术有限公司 | 拉力机-万能试验机-材料拉伸试验机-电子拉力机-拉力试验机厂家-冲击试验机-苏州皖仪实验仪器有限公司 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 雷达液位计_超声波风速风向仪_雨量传感器_辐射传感器-山东风途物联网 | 湖南教师资格网-湖南教师资格证考试网 | 主题班会网 - 安全教育主题班会,各类主题班会PPT模板 | 预制围墙_工程预制围墙_天津市瑞通建筑材料有限公司 | 博博会2021_中国博物馆及相关产品与技术博览会【博博会】 | 福尔卡(北京)新型材料技术股份有限公司 |