javascript - Dimple.JS Animate 线条系列动画

标签 javascript d3.js dimple.js

我正在尝试使用 Dimple.js 实现图表,下面是我尝试分别为两个系列(此处为条形图和线条)设置动画的代码,但它看起来像线条系列动画像条形系列(从下到上) 。然而,我期待更像在这里执行的动画:http://bl.ocks.org/duopixel/4063326

<div id="divBarWithLineChart" class="DimpleChart"></div>


    var width = $('#divBarWithLineChart').width();

    var height = $('#divBarWithLineChart').height();

    var svg = dimple.newSvg("#divBarWithLineChart", width - 20, height);

    d3.json("Scripts/Data/Data.json", function (data) {
        // Filter the data for a single channel
        data = dimple.filterData(data, "Channel", "Hypermarkets");

        // Create the chart
        var myChart = new dimple.chart(svg, data);
        myChart.setBounds(60, 30, 470, 300)

        // Add an x and 2 y-axes.  When using multiple axes it's
        // important to assign them to variables to pass to the series
        var x = myChart.addCategoryAxis("x", "Brand");
        var y1 = myChart.addMeasureAxis("y", "Price");
        var y2 = myChart.addMeasureAxis("y", "Sales Value");

        // Order the x axis by sales value desc
        x.addOrderRule("Sales Value", true);

        // Color the sales bars to be highly transparent
        myChart.assignColor("Sales", "#222222", "#000000", 0.1);

        // Add the bars mapped to the second y axis
        myChart.addSeries("Sales", dimple.plot.bar, [x, y2]);

        // Add series for minimum, average and maximum price
        var min = myChart.addSeries("Min", dimple.plot.line, [x, y1]);
        min.aggregate = dimple.aggregateMethod.min;

        myChart.setMargins("70px", "30px", "70px", "70px");

        myChart.assignColor("Sales", "#083f65", "#083f65", 1);
        myChart.assignColor("Min", "#c62828", "#c62828", 1);

        myChart.staggerDraw = true;
        myChart.ease = "bounce";
        myChart.draw(1000);

是否可以单独制作线系列动画?有人可以帮忙吗?

提前致谢...

最佳答案

是的,这是可能的。如果您检查 chrome 开发人员栏中的 svg 行,它是一个可以使用 css 进行动画处理的 svg 路径...路径类名称是 dimple-line。因此,只需为这个类名添加一些 css,当绘制线条时,它会完全模仿 d3 示例(在我的网站 http://dimplejs.org 上尝试过)并且它工作得很好......

<style>
    .dimple-line {
        stroke-dasharray: 1000;
        stroke-dashoffset: 1000;
        animation: dash 5s linear forwards;
    }

    @keyframes dash {
        to {
            stroke-dashoffset: 0;
        }
    }
</style>

或者想要虚线效果试试这个...

.dimple-line {
        stroke-dasharray: 20;
        stroke-dashoffset: 1000;
        animation: dash 5s linear forwards;
    }

    @keyframes dash {
        to {
            stroke-dashoffset: 0;
        }
    }

请参阅此站点以了解此技术的其他变体... https://css-tricks.com/svg-line-animation-works/

关于javascript - Dimple.JS Animate 线条系列动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39622341/

相关文章:

javascript - SVG指示器,而ajax收集所有信息(D3.js)

javascript - 如何使用dimple.js按不同数据行对y轴进行排序

javascript - 如何以函数方式修改对象的所有属性

javascript - 类型错误 : Cannot read property '_rawValidators' of null after Ng build

javascript - 我的正则表达式在在线编辑器中有效,但在 FireBug 中它会使浏览器崩溃

javascript - 如何在标题标签中放置滚动文本?

javascript - d3.js 在每个条的末尾堆叠条形图值

javascript - 如何将 svg 移动/平移到某个位置?

jquery - 生成带有虚线填充线的 SVG 矩形

javascript - 为什么dimple.js 示例需要 Web 服务器才能运行?