Coder Social home page Coder Social logo

Comments (3)

aglenis avatar aglenis commented on June 18, 2024

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.

aglenis avatar aglenis commented on June 18, 2024

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.

aglenis avatar aglenis commented on June 18, 2024

I had to create the x and y axis for the code to work.

from scala-js-d3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.