首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >D3Plus工具提示舍入值

D3Plus工具提示舍入值
EN

Stack Overflow用户
提问于 2016-08-19 22:49:00
回答 1查看 380关注 0票数 0

我有一个很大值的条形图。现在,工具提示会显示"Value: 142M",但我希望它显示的是确切的数量: 141751760。我需要更改什么配置才能实现这一点?

代码语言:javascript
复制
// load your data
var sample_data = [
  {"date": "05 Aug", "name":"events", "value": 141751760},
  {"date": "06 Aug", "name":"events", "value": 137933833},
  {"date": "07 Aug", "name":"events", "value": 132537452},
  {"date": "08 Aug", "name":"events", "value": 120686130},
  {"date": "09 Aug", "name":"events", "value": 228518696},
  {"date": "10 Aug", "name":"events", "value": 133506681},
  {"date": "11 Aug", "name":"events", "value": 132956555},
  {"date": "12 Aug", "name":"events", "value": 129211690},
  {"date": "13 Aug", "name":"events", "value": 134858225},
  {"date": "14 Aug", "name":"events", "value": 116100660}
]
var attributes = [
  {"name": "events", "hex": "#178acc"}
]

// instantiate d3plus
var visualization = d3plus.viz()
  .container("#viz")  // container DIV to hold the visualization  
  .data(sample_data)  // data to use with the visualization 
  .type("bar")       // visualization type
  .id("name")         // key for which our data is unique on
  .y("value")         // key to use for y-axis
  .x("date")          // key to use for x-axis 
  .attrs(attributes) 
  .color("hex")
  .tooltip(["date", "value"])
  .draw()             // finally, draw the visualization!
EN

回答 1

Stack Overflow用户

发布于 2016-08-19 22:55:59

你没有显示任何代码,所以我不能给你一个工作的样本。但您可以添加格式以按您想要的方式格式化:

代码语言:javascript
复制
.format({
  "number": function(number, params) {
    return number; // No formatting
  }
})

您可以将其与条形图的其余部分链接在一起。

编辑:

来自here的格式化函数

代码语言:javascript
复制
function customFormat(x) {
    var parts = x.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}
var visualization = d3plus.viz()
  .container("#viz")  // container DIV to hold the visualization  
  .data(sample_data)  // data to use with the visualization 
  .type("bar")       // visualization type
  .id("name")         // key for which our data is unique on
  .format({
      "number": function(number, params) {
          return customFormat(number);
      }
  })
  .y("value")         // key to use for y-axis
  .x("date")          // key to use for x-axis 
  .attrs(attributes) 
  .color("hex")
  .tooltip(["date", "value"])
  .draw();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39041971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档