javascript - 使用 D3.js (v4) 制作折线图动画?

标签 javascript jquery d3.js

是否可以使用 D3.js(版本 4)创建动画?特别是我想创建多个从左到右“运行”的折线图,就像这个例子中的 react-fusionchart:

http://jsfiddle.net/thadeuszlay/m18qaekm/12/

(只看上面的例子。)

FusionCharts.ready(function () {
    var myDataSource = {
        "chart": {
            "caption": "Actual Revenues, Targeted Revenues & Profits",
                "subcaption": "Last year",
                "xaxisname": "Month",
                "yaxisname": "Amount (In USD)",
                "numberprefix": "$",
                "theme": "ocean"
        },
            "categories": [{
            "category": [{
                "label": "Jan"
            }, {
                "label": "Feb"
            }, {
                "label": "Mar"
            }, {
                "label": "Apr"
            }, {
                "label": "May"
            }, {
                "label": "Jun"
            }, {
                "label": "Jul"
            }, {
                "label": "Aug"
            }, {
                "label": "Sep"
            }, {
                "label": "Oct"
            }, {
                "label": "Nov"
            }, {
                "label": "Dec"
            }]
        }],
            "dataset": [{
            "seriesname": "Projected Revenue",
                "renderas": "line",
                "showvalues": "0",
                "data": [{
                "value": "15000"
            }, {
                "value": "16000"
            }, {
                "value": "17000"
            }, {
                "value": "18000"
            }, {
                "value": "19000"
            }, {
                "value": "19000"
            }, {
                "value": "19000"
            }, {
                "value": "19000"
            }, {
                "value": "20000"
            }, {
                "value": "21000"
            }, {
                "value": "22000"
            }, {
                "value": "23000"
            }]
        }]
    };

    var chartConfigs = {
        id: "revenue-profits-chart",
        renderAt: "revenue-profits-chart-container",
        type: "mscombi2d",
        width: 600,
        height: 400,
        dataFormat: "json",
        dataSource: myDataSource
    };

    React.render( < react_fc.FusionCharts {...chartConfigs
    }
    />,
        document.getElementById("chart-container")
    );
});

最佳答案

是的,你可以这样做:你只需要替换从 d3 v3 到 v4 的方法,例如:

var parse = d3.timeParse("%b %Y");
var x = d3.scaleTime().range([0, width]),
    y = d3.scaleLinear().range([height, 0]),
    xAxis = d3.axisBottom(x).tickSize(-height),
    yAxis = d3.axisLeft(y).tickArguments(4);

等等。等等

您可以找到 working example on my bl.ocks . 我的示例是 another bl.ocks 的 v4 更新. 希望对您有所帮助。

关于javascript - 使用 D3.js (v4) 制作折线图动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39885571/

相关文章:

javascript - 使用 webpack 加载 CSS 时,我可以为标签编​​写 CSS,但不能为类或 ID 编写

javascript - 单击事件后重定向 url 并更改页面,并使用 GET 将 html 文件提供给浏览器

javascript - 通过 DOM 获取值,然后过滤数组以获取该值返回未定义

javascript - 是(:visible) selector not working on class jQuery

jQuery 根据浏览器返回不同的顶部和左侧值

Javascript 正则表达式测试()错误 : Object has no method 'test'

javascript - 如何使用 Canvas 处理多个按键

javascript - 全宽 div 在滚动时消失

javascript - 如何为 D3 svg 中数据的每个元素附加 <text>

d3.js - D3:创建一个连续的色标,其中包含用于范围的许多字符串/输入并动态更改域的值