如何使用 g.raphael 或 jquery svg 创建具有两种不同比例的折线图?

发布于 2024-10-14 10:27:08 字数 182 浏览 4 评论 0原文

我需要绘制类似于此处的图表的扭矩曲线 http://www.fordscorpio.co.uk /flatspot.htm 在 javascript 中..最好使用 g.raphael。欢迎任何建议。谢谢你!

I need to plot a torque curve similar to the graph here http://www.fordscorpio.co.uk/flatspot.htm in javascript..preferably using g.raphael. Any suggestions are welcome. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人的歌 2024-10-21 10:27:08

您可以按如下方式创建自己的轴对象。 (已经丢失了此代码段的源/要点 URL,因此无法在应有的位置给出信用)

axis = r.g.axis(85,230,310,null,null,4,2,["1",  "2", "3", "4"], "|", 0);
axis.text.attr({font:"12px Arial", "font-weight": "regular", "fill": "#333333"});
// y-axis denoted by setting orientation to 1 
axis2 = r.g.axis(40,230,300,0,400,10,1);

因此,创建一个包含两个系列的普通折线图,然后绘制另一个轴

否则,设置多个轴,然后调整标签:-

var lines = r.g.linechart(10, 10, 300, 220, [[1, 2, 3, 4, 5, 6, 7],[3.5, 4.5, 5.5, 6.5, 7, 8]], [[12, 32, 23, 15, 17, 27, 22], [10, 20, 30, 25, 15, 28]], {nostroke: false, axis: "1 1 1 1", symbol: "o", smooth: true});
lines.axis[0].text.items[3].attr('text','my label');

You can create your own axis objects as follows. (Have lost the source/gist URL for this snippet so can't give credit where it's due)

axis = r.g.axis(85,230,310,null,null,4,2,["1",  "2", "3", "4"], "|", 0);
axis.text.attr({font:"12px Arial", "font-weight": "regular", "fill": "#333333"});
// y-axis denoted by setting orientation to 1 
axis2 = r.g.axis(40,230,300,0,400,10,1);

So create a normal line graph with two series and then draw another axis

Otherwise, set up multiple axes and then tweak the labels :-

var lines = r.g.linechart(10, 10, 300, 220, [[1, 2, 3, 4, 5, 6, 7],[3.5, 4.5, 5.5, 6.5, 7, 8]], [[12, 32, 23, 15, 17, 27, 22], [10, 20, 30, 25, 15, 28]], {nostroke: false, axis: "1 1 1 1", symbol: "o", smooth: true});
lines.axis[0].text.items[3].attr('text','my label');
余罪 2024-10-21 10:27:08

http://g.raphaeljs.com/linechart.html

这是带有 3 个不相关的脚本删除的图表:

        window.onload = function () {

            var r = Raphael("holder");

            r.g.txtattr.font = "12px 'Fontin Sans', Fontin-Sans, sans-serif";



            var x = [], y = [], y2 = [], y3 = [];

            for (var i = 0; i < 1e6; i++) {

                x[i] = i * 10;

                y[i] = (y[i - 1] || 0) + (Math.random() * 7) - 3;

                y2[i] = (y2[i - 1] || 150) + (Math.random() * 7) - 3.5;

                y3[i] = (y3[i - 1] || 300) + (Math.random() * 7) - 4;

            }





            r.g.text(160, 10, "Symbols, axis and hover effect");

(功能 () {

            var lines = r.g.linechart(10, 10, 300, 220, [[1, 2, 3, 4, 5, 6, 7],[3.5, 4.5, 5.5, 6.5, 7, 8]], [[12, 32, 23, 15, 17, 27, 22], [10, 20, 30, 25, 15, 28]], {nostroke: false, axis: "0 0 1 1", symbol: "o", smooth: true}).hoverColumn(function () {

                this.tags = r.set();

                for (var i = 0, ii = this.y.length; i < ii; i++) {

                    this.tags.push(r.g.tag(this.x, this.y[i], this.values[i], 160, 10).insertBefore(this).attr([{fill: "#fff"}, {fill: this.symbols[i].attr("fill")}]));

                }

            }, function () {

                this.tags && this.tags.remove();

            });

            lines.symbols.attr({r: 3});

            // lines.lines[0].animate({"stroke-width": 6}, 1000);

            // lines.symbols[0].attr({stroke: "#fff"});

            // lines.symbols[0][1].animate({fill: "#f00"}, 1000);

        };

    </script>

http://g.raphaeljs.com/linechart.html

Here is the script with the 3 irrelevant graphs removed:

        window.onload = function () {

            var r = Raphael("holder");

            r.g.txtattr.font = "12px 'Fontin Sans', Fontin-Sans, sans-serif";



            var x = [], y = [], y2 = [], y3 = [];

            for (var i = 0; i < 1e6; i++) {

                x[i] = i * 10;

                y[i] = (y[i - 1] || 0) + (Math.random() * 7) - 3;

                y2[i] = (y2[i - 1] || 150) + (Math.random() * 7) - 3.5;

                y3[i] = (y3[i - 1] || 300) + (Math.random() * 7) - 4;

            }





            r.g.text(160, 10, "Symbols, axis and hover effect");

(function () {

            var lines = r.g.linechart(10, 10, 300, 220, [[1, 2, 3, 4, 5, 6, 7],[3.5, 4.5, 5.5, 6.5, 7, 8]], [[12, 32, 23, 15, 17, 27, 22], [10, 20, 30, 25, 15, 28]], {nostroke: false, axis: "0 0 1 1", symbol: "o", smooth: true}).hoverColumn(function () {

                this.tags = r.set();

                for (var i = 0, ii = this.y.length; i < ii; i++) {

                    this.tags.push(r.g.tag(this.x, this.y[i], this.values[i], 160, 10).insertBefore(this).attr([{fill: "#fff"}, {fill: this.symbols[i].attr("fill")}]));

                }

            }, function () {

                this.tags && this.tags.remove();

            });

            lines.symbols.attr({r: 3});

            // lines.lines[0].animate({"stroke-width": 6}, 1000);

            // lines.symbols[0].attr({stroke: "#fff"});

            // lines.symbols[0][1].animate({fill: "#f00"}, 1000);

        };

    </script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文