Comments (3)
I also tried a simpler example from here:
http://thecodingtutorials.blogspot.com/2012/07/introduction-to-d3.html
val graphHeight = 450
//The width of each bar.
val barWidth = 80
//The distance between each bar.
val barSeparation = 10
//The maximum value of the data.
val maxData = 50
//The actual horizontal distance from drawing one bar rectangle to drawing the next.
val horizontalBarDistance = barWidth + barSeparation
//The value to multiply each bar's value by to get its height.
val barHeightMultiplier = graphHeight / maxData;
//Color for start
val color = d3.rgb("DarkSlateBlue")
val my_data = js.Array(8, 22, 31, 36, 48, 17, 25)
val rectXFun = (d: Int, i: Int) => i * horizontalBarDistance
val rectYFun = (d: Int) => graphHeight - d * barHeightMultiplier
val rectXFun2 = (d: Int, i: Int) => i * horizontalBarDistance +5
val rectYFun2 = (d: Int) => graphHeight - d * barHeightMultiplier +15
val rectHeightFun = (d: Int) => d * barHeightMultiplier
val rectColorFun = (d: Int, i: Int) => color.brighter(i * 0.5).toString
val remove_element = d3.select("#d3Container2").select("svg").remove()
val svg = d3.select("#d3Container2").append("svg").attr("width", "100%").attr("height", "450px")
val sel = svg.selectAll("rect").data(my_data)
val data_enter = sel.enter()
val sel2 = data_enter
.append("rect")
.attr("x", rectXFun)
.attr("y", rectYFun)
.attr("width", barWidth)
.attr("height", rectHeightFun)
.style("fill", rectColorFun)
val textXOffset = horizontalBarDistance / 2 - 12
val textYOffset = 20
val textYPosition = graphHeight + textYOffset;
//Draw the text.
data_enter.append("text").text((d: Int) => d.toString)
.attr("x", (d: Int,i: Int) => i * horizontalBarDistance + textXOffset)
.attr("y", textYPosition);
And it still does not work.
Can you please help me?
from scala-js-d3.
I also tried adding a title to the graph using:
svg.append("text")
//.attr("x", (width / 2))
//.attr("y", 0 - (margin.top / 2))
.text("Graph Title")
.attr("text-anchor", "middle")
.style("font-size", "16px")
.style("text-decoration", "underline")
.style("fill","blue")
.style("color","blue")
But only the underline gets shown.
from scala-js-d3.
I had to create the x and y axis for the code to work.
from scala-js-d3.
Related Issues (20)
- Additional implicits for several svg functions
- layout.partition HOT 4
- Cannot use call HOT 4
- Support latest version of D3 HOT 4
- timeModule.Scale isn't compatible with behavior.zoom.Scale HOT 3
- Usage of DatumFunction HOT 6
- Possible issue to selection.data HOT 5
- Key function signature does not seem to match d3 documentation HOT 4
- Empty update selection HOT 2
- Question on radial HOT 2
- Adding area as "d" attribute HOT 6
- Testing with uTest HOT 4
- .each and d3.select(this) HOT 2
- Support for D3js 4.x HOT 5
- 0.3.4 only published for Scala 2.12 HOT 1
- Should 'd3.scala' be a trait rather than object? HOT 2
- Ambiguous reference to a JS library: 3.5.17/d3.min.js
- Support scala-js 1.X
- selection.data key with simple function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala-js-d3.