如何访问 G. Raphael 折线图中的单条线并设置其样式
由于 raphael JS 库的文档非常少,我恳求集体智慧。
我有一个工作g。 raphael 多线折线图(类似于 http://g.raphaeljs.com/linechart.html)
类似: var lineChart = rglinechart(10,10,300,220,[1,2,3,4,5],[[10,20,15,35,30],[5,10,5,15,20]], {阴影: true, "颜色":["#44F","#CCC"], nolines:true});
我想更改其中一行来设置填充 = 清除和描边 = 颜色
我被告知这样的东西可以工作,但没有运气 - 有什么建议吗? lineChart.lines[0].attr({lines: "#000"}),
额外加分,如何将线条的填充设置为渐变?
谢谢!
Due to the very poorly documented raphael JS library, I beseech the collective wisdom.
I have a working g. raphael multi-line line chart (similar to http://g.raphaeljs.com/linechart.html)
something like:
var lineChart = r.g.linechart(10,10,300,220,[1,2,3,4,5],[[10,20,15,35,30],[5,10,5,15,20]], {shade:true, "colors":["#44F","#CCC"], nostroke:true});
I'd like to change one of the lines to set the fill = clear and stroke = a color
I was told something like this would work, but no luck -any suggestions?
lineChart.lines[0].attr({stroke: "#000"}),
for extra credit, how can I set the fills of a line to a gradient?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用 Firebug 和 console.log() 列出一行上的属性:
我单击日志行以查看详细信息,如下所示:
对于我来说,我想更改笔画宽度。此代码有效:
优秀的 RaphaelJS 文档中列出了
line-width
属性。对于您的问题,我希望您需要这样的代码:
我希望这有帮助!
I used Firebug and console.log() to list the attributes on a line:
I clicked on the log line to see the details, like this:
For me, I wanted to change the stroke-width. This code works:
The
line-width
attribute is listed in the excellent RaphaelJS documentation.For your problem, I expect you need code like this:
I hope this helps!
以下是我通过反复试验发现的一些事情。当我发现更多时会更新。正如你所说,如果 gRaphael 实际上拥有像真实项目一样的文档,那就更好了……尽管它似乎最近已经移交,所以希望事情会有所改变。
lineChart.lines
lineChart.symbols
lineChart.axis
{axis: "0 0 1 1"}
),那么axis[0]
将是 X 轴,< code>axis[1] Y。如果有左、下、右,右将是axis[0]
,bottomaxis[1]、左
axis[2]
等lineChart.axis[n].text
(其中 n是您想要的轴的编号,如上所述)Here are some things I found by trial and error. Will update as I discover more. As you say, it'd be so much better if gRaphael actually had documentation like a real project... although it seems it's recently been handed over so hopefully things will change.
lineChart.lines
lineChart.symbols
lineChart.axis
{axis: "0 0 1 1"}
), thenaxis[0]
will be the X axis andaxis[1]
the Y. If you have a left, bottom, and right, the right will beaxis[0]
,bottomaxis[1]
, leftaxis[2]
, etc.lineChart.axis[n].text
(where n is the number, as above, of the axis you want)肯尼·沉建议
kenny shen advises
我没有使用 Raphäel,但您应该能够将填充设置为透明并为描边设置颜色。如果 SVG 元素有 ID 或类,那么您应该能够通过 CSS 进行设置:
否则,您可以使用
path:nth-of-type()
来选择该元素,或者选择该元素就像你在 JS 中的任何其他操作一样,设置描边和填充属性。上面的代码中有
norinkle: true
。我不确定这是否会阻止它按您的预期工作。要设置渐变(至少在真实的 SVG 中),请将 fill 属性的值设置为指向 id 的 url。然后,您可以使用该 ID 创建一个 LinearGradient 元素。请参阅此示例了解如何编写渐变。您还可以在 SVG 中将笔画的值设置为渐变。
I've not used Raphäel, but you should be able to set the fill to transparent and set a colour to the stroke. If the SVG element has an ID or class then you should be able to set this via CSS:
Otherwise, you could use
path:nth-of-type()
to select the element, or select the element like you would any other in JS and set the stroke and fill attributes.You have
nostroke: true
in the code above. I'm not sure if that is stopping it from working as you expected.To set a gradient (at least in real SVG) you set the value of the fill attribute to a url, pointing to an id. You then create a linearGradient element with that ID. See this example of how to write gradients. You can also set the value of a stroke to a gradient too in SVG.