首页 \ 问答 \ 更新折线图(Updating line graph)

更新折线图(Updating line graph)

我正在寻找更新我的折线图的最佳方法。 传入的数据不是“新的”,它只是在许多不同的数据集之间切换。 我的问题是.append('path')根本不起作用,我不知道为什么。 它可能与我的分组有关:我喜欢在图表周围加上边距,因此轴和标签不会被剪裁。 为此,我的HTML看起来如下......

<svg w, h id='svg-container'>
  <g translate(w - margin, h - margin) id='chart-container'>
    <g id='x-axis'>
    <g id='y-axis'>

在我的代码中,我想选择chart-container并附加<path d='...' id='line'> 。 稍后,在更新图表时,我希望能够简单地select('chart-container').select('path')并更新该选择。

图表的初始设置:

var svgContainer = d3.select(element[0]).append('svg')
    .attr({
        width: width + margin.left + margin.right,
        height: height + margin.top + margin.bottom
    })
    .classed('svg-container', true);

var chartContainer = svgContainer.append('g')
  .classed('chart-container', true)
  .attr('transform', "translate(" + margin.left + "," + margin.top + ")");

chartContainer.append('path')
 .data(activeData)
 .attr('d', lineFunc)
 .attr('stroke', 'blue')
 .attr('stroke-width', 
 .attr('fill', 'none');

稍后更新图表:

svgContainer = d3.select('#line-container').select('.svg-container')
    .attr({
        width: width + margin.left + margin.right,
        height: height + margin.top + margin.bottom
    });

chartContainer = svgContainer.select('.chart-container')
    .attr('transform', "translate(" + margin.left + "," + margin.top + ")");

chartContainer.select('path')
     .data(activeData)
     .attr('d', lineFunc)
     .attr('stroke', 'blue')
     .attr('stroke-width', 
     .attr('fill', 'none');

不幸的是,这不起作用,我不知道为什么。 最初的chartContainer.append('path')似乎正在工作(有时),而chartContainer.select('path')实际上并没有返回正确的项目(othertimes)。 可能d3要遍历我的轴组并返回其中一条路径? 我是以错误的方式来做这件事的吗?


I'm looking for the best way to update my line graph. The incoming data is not 'new', it's just switching between many different data sets. My issue is that .append('path') simply isn't working, and I'm not sure why. It may have to do with my grouping: I like to put margins around my graphs so axis and labels aren't clipped. To do this, my HTML looks like the following...

<svg w, h id='svg-container'>
  <g translate(w - margin, h - margin) id='chart-container'>
    <g id='x-axis'>
    <g id='y-axis'>

In my code I would like to select chart-container and append a <path d='...' id='line'>. Later, when updating the graph, I would hope to be able to simply select('chart-container').select('path') and update that selection.

Initial setup of the chart:

var svgContainer = d3.select(element[0]).append('svg')
    .attr({
        width: width + margin.left + margin.right,
        height: height + margin.top + margin.bottom
    })
    .classed('svg-container', true);

var chartContainer = svgContainer.append('g')
  .classed('chart-container', true)
  .attr('transform', "translate(" + margin.left + "," + margin.top + ")");

chartContainer.append('path')
 .data(activeData)
 .attr('d', lineFunc)
 .attr('stroke', 'blue')
 .attr('stroke-width', 
 .attr('fill', 'none');

Update the chart later on:

svgContainer = d3.select('#line-container').select('.svg-container')
    .attr({
        width: width + margin.left + margin.right,
        height: height + margin.top + margin.bottom
    });

chartContainer = svgContainer.select('.chart-container')
    .attr('transform', "translate(" + margin.left + "," + margin.top + ")");

chartContainer.select('path')
     .data(activeData)
     .attr('d', lineFunc)
     .attr('stroke', 'blue')
     .attr('stroke-width', 
     .attr('fill', 'none');

Unfortunately this doesn't work, and I'm not sure why. The initial chartContainer.append('path') seem to be working (sometimes), and the chartContainer.select('path') doesn't actually return the correct item (othertimes). Might d3 be traversing my axis groups and returning one of their paths? Am I going about this the wrong way?


原文:https://stackoverflow.com/questions/18992415
更新时间:2021-12-06 16:12

最满意答案

即使按字典顺序,2位数的日期和工作号仍应正确排序。 但是,如果您涉及到2000之前的数据,那么您需要:

(包括样本表 - 只需忽略)

drop table if exists jobnumbers ;
create table jobnumbers (id int primary key, number varchar(10)); 
insert jobnumbers values
(  1, 'J09-1893'),
(  2, 'J11-1323'),
(  3, 'J08-0011'),
(  4, 'J09-0234'),
(  5, 'J10-1232'),
(  6, 'J11-1111'),
(  9, 'J99-1111');

select *
from jobnumbers
order by 
  case when number>'J5' then 1900 else 2000 end desc, number desc;

至于indexing (因为你标记了它),有两个选择:

  1. 你必须将它分成多个列才能索引年份,然后是工作号码
  2. 使用4位数年份。

The 2-digit dates and job numbers should still sort correctly, even lexicographically. But, if you had pre-2000 data involved, then you need this:

(sample table included - just ignore)

drop table if exists jobnumbers ;
create table jobnumbers (id int primary key, number varchar(10)); 
insert jobnumbers values
(  1, 'J09-1893'),
(  2, 'J11-1323'),
(  3, 'J08-0011'),
(  4, 'J09-0234'),
(  5, 'J10-1232'),
(  6, 'J11-1111'),
(  9, 'J99-1111');

select *
from jobnumbers
order by 
  case when number>'J5' then 1900 else 2000 end desc, number desc;

As for indexing (since you tagged it), two options:

  1. you would have to split that into multiple columns to be able to index on year, then job number
  2. Use 4-digit years.

相关问答

更多
  • 不知道这是否符合简单: order by case when currency = 'USD' then 1 when currency = 'BHT' then 2 when currency = 'JPY' then 3 when currency = 'MYR' then 4 else 5 end 或者比较紧凑但是Oracle具体: order by decode(currency, 'USD', 1, 'B ...
  • 在CASE ,您可以将数值归于每个,并对这些值进行排序。 如果您需要查询大表,请考虑在Description上添加索引以提高排序性能。 ORDER BY CASE WHEN Description = 'Gold - owned' THEN 0 WHEN Description = 'Silver - identified / offered' THEN 1 WHEN Description = 'Bronze - no land' THEN 2 ELSE 99 /* ...
  • 试试以下: ORDER BY CASE Category WHEN 'Pettycash' THEN '1' WHEN 'DailyExpense' THEN '2' WHEN 'Home Expense' THEN '3' WHEN 'Fair Expense' THEN '4' WHEN 'Cash Expense' THEN '5' ELSE '6' END 在此处找到文档。 Try following: ORDER BY CASE Category WH ...
  • 即使按字典顺序,2位数的日期和工作号仍应正确排序。 但是,如果您涉及到2000之前的数据,那么您需要: (包括样本表 - 只需忽略) drop table if exists jobnumbers ; create table jobnumbers (id int primary key, number varchar(10)); insert jobnumbers values ( 1, 'J09-1893'), ( 2, 'J11-1323'), ( 3, 'J08-0011'), ( 4, ...
  • 我不认为SQL提供程序支持将lambda列添加到查询中。 但是,它确实支持coalesce操作符,因为你基本上是这样做的: SELECT * FROM Tasks ORDER BY ISNULL(DueDate, DATEADD(year, 10, GETDATE())) 尝试这个: from o in dc.Orders orderby o.DueDate ?? DateTime.Today.AddYears(10) 如果你需要假的,将来的日期也出于某种原因在你的结果集中,你可以在LINQtoSQL ...
  • 一个选项是CTE: with ordering as ( select v.* from (values(1, 'val1'), (2, 'val2'), (3, 'val3')) v(priority, val) ) select e.* from example e order by (select priority from ordering o where o.val = e.name); 我会阻止你进行显式join ,因为这可能会影响查询的语义。 在select ...
  • SQL是通过Universe确定的,对象被拖入WebI文档的顺序确实影响了BO如何生成SQL。 听起来您正在寻找更改from子句的构建方式,这几乎总是需要对Universe进行更改,而不是将对象引入WebI查询构建器的顺序。 您可能能够更好地了解如何更改Universe以在Dave Rathbun的博客上生成正确/更好的SQL,尤其是他关于上下文的文章。 Business Objects has a super secret setting in the Universe Designer Properti ...
  • 如果没有表格设计和字段,列,键,......,很难帮助你。 但我会体谅: 1 - 主键字段,以及如何关联表 2 - 如何使用“过滤器”添加左连接,或如何减少结果数量 3 - 评估使用子查询是否更好 另外:尝试使用TOP 100 <---进行查询以进行测试。 请记住:有时由于硬件限制(例如RAM)而优化查询是不可能的,在这种情况下,您必须分段显示数据。 It's dificult to help you without the tables design and fields|columns, keys, . ...
  • 尝试这个: SELECT x FROM t1 ORDER BY CASE WHEN x = 1 THEN 100000001 WHEN x between 2 and 7 THEN 7 - x WHEN x between 8 and ( SELECT max(x) FROM t1 ) - 1 THEN x ELSE 100000000 END 1000000个常数必须比N大。 这是一个简单的演示 Try this: SELECT x F ...
  • 一种解决方案是只使用子查询: SELECT t.* FROM ((SELECT 'First Query' as QRY, Field1, Field2 FROM Tabl1 WHERE Field1 <= 5 ) UNION ALL (SELECT 'Second Query', Field1, Field2 FROM Tabl1 WHERE Field1 > 5 ) ) t ORDER BY QRY, ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)