0

A very basic SVG/JavaScript question: How do you set the width and height of an SVG object (polygon, path, ellipse, etc.) via JavaScript?

This is my first interactive SVG after years of working in ActionScript. I'm just trying to set the height of bars in a bar chart dynamically. I've gotten quite a ways into this project setting fill color and visibility of various objects with pedestrian code like this:

targetbar=document.getElementById("rep"+loopcount);
targetbar.setAttribute("visibility", "visible");

But plugging height and a number into the setAttribute command does not work, nor has anything else I've copied from various code snippets found online.

Thinking that I'd keep this first project as plain-vanilla as possible, I haven't been using any external libraries. At least for now I'm looking for a solution that doesn't involve JQuery, Raphael, D3, etc.

4

1 回答 1

0

SVG 中的大多数元素根本没有高度和宽度属性。多边形具有顶点坐标集,路径具有各种路径对象的坐标,椭圆具有半长轴和半短轴半径。

您可以通过在其上设置一个变换属性来缩放形状,该属性将按比例调整宽度和高度,例如 transform="scale(1.1, 0.9)" 将使任何形状比正常情况稍宽且不那么高。

于 2013-06-26T08:38:30.897 回答