javascript - Is it possible to do Subscripting in SVG? -
i have drawn bar chart using dimple.js. have show yaxis labels , xaxis lables subscript. possible show subscript in svg. if yes please let me know how achieve subscripting in svg.
fiddle - http://jsfiddle.net/keshav_1007/utfnlaz6/3/
var ymax = 1.2; var svg1 = dimple.newsvg("body", 360, 360); var datachart = [{ "brand": "aaaaaaaaaaaaaaaaaaaaaa", "day": "mon", "so2": 10 }, { "brand": "bbbbbbbbbbbbbbbbbbbb", "day": "mon", "so2": 20 }, { "brand": "ccccccccccccccccc", "day": "mon", "so2": 20 }]; var mychart = new dimple.chart(svg1, datachart); mychart.setbounds(120, 10, 200, 200) var x = mychart.addcategoryaxis("x", "day"); var y = mychart.addmeasureaxis("y", "so2"); y.ticks = 5; var s = mychart.addseries("brand", dimple.plot.bar); s.bargap = 0.7; mychart.draw(); console.log(y._tick_step)
in have so2 2 subscript. please let me know how that.
here's quick hack. after plot drawn do:
var label = d3.select('.dimple-title.dimple-axis-y') //<-- find axis label d3.select(label.node().parentnode) //<-- add new text subscript 2 .append('text') .attr('transform', label.attr('transform')) .attr('style', label.attr('style')) .attr('x', +label.attr('x') + 6) .attr('y', label.attr('y') - 5) .text('2');
full code:
var ymax = 1.2; var svg1 = dimple.newsvg("body", 360, 360); var datachart = [{ "brand": "aaaaaaaaaaaaaaaaaaaaaa", "day": "mon", "so": 10 }, { "brand": "bbbbbbbbbbbbbbbbbbbb", "day": "mon", "so": 20 }, { "brand": "ccccccccccccccccc", "day": "mon", "so": 20 }]; var mychart = new dimple.chart(svg1, datachart); mychart.setbounds(120, 10, 200, 200) var x = mychart.addcategoryaxis("x", "day"); var y = mychart.addmeasureaxis("y", "so"); y.ticks = 5; var s = mychart.addseries("brand", dimple.plot.bar); s.bargap = 0.7; mychart.draw(); console.log(y._tick_step) var label = d3.select('.dimple-title.dimple-axis-y') d3.select(label.node().parentnode) .append('text') .attr('transform', label.attr('transform')) .attr('style', label.attr('style')) .attr('x', +label.attr('x') + 6) .attr('y', label.attr('y') - 5) .text('2');
<script src="http://d3js.org/d3.v3.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/dimple/2.1.6/dimple.latest.min.js"></script>
Comments
Post a Comment