Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:21:52+00:00 2026-06-15T05:21:52+00:00

Here is a link to the jsfiddle http://jsfiddle.net/jaimem/RPGPL/2/ Now the graph shows red color

  • 0

Here is a link to the jsfiddle

http://jsfiddle.net/jaimem/RPGPL/2/

Now the graph shows red color for all the circles.Is dere a way to show random colors on the circles.

Here is the d3.js code

 var data = [{ "count": "202", "year": "1590"},
                  { "count": "215", "year": "1592"},
                  { "count": "179", "year": "1593"}, 
                  { "count": "199", "year": "1594"},
                  { "count": "134", "year": "1595"},
                  { "count": "176", "year": "1596"},
                  { "count": "172", "year": "1597"},
                  { "count": "161", "year": "1598"},
                  { "count": "199", "year": "1599"},
                  { "count": "181", "year": "1600"},
                  { "count": "157", "year": "1602"},
                  { "count": "179", "year": "1603"},
                  { "count": "150", "year": "1606"},
                  { "count": "187", "year": "1607"},
                  { "count": "133", "year": "1608"},
                  { "count": "190", "year": "1609"},
                  { "count": "175", "year": "1610"},
                  { "count": "91", "year": "1611"},
                  { "count": "150", "year": "1612"} ];



function ShowGraph(data) {
d3.selectAll('.axis').remove();
var vis = d3.select("#visualisation").append('svg'),
    WIDTH = 500,
    HEIGHT = 500,
    MARGINS = {
        top: 20,
        right: 20,
        bottom: 20,
        left: 30
    },
                xRange = d3.scale
                       .linear()
                       .domain([
                          d3.min(data, function(d){ return parseInt(d.year, 10);}),
                          d3.max(data, function(d){ return parseInt(d.year, 10);})
                        ])
                       .range([MARGINS.left, WIDTH - MARGINS.right]),
            yRange = d3.scale
                       .linear()
                       .domain([
                          d3.min(data, function(d){ return parseInt(d.count, 10);}),
                          d3.max(data, function(d){ return parseInt(d.count, 10);})
                        ])
                       .range([HEIGHT - MARGINS.top, MARGINS.bottom]),

    xAxis = d3.svg.axis() // generate an axis
    .scale(xRange) // set the range of the axis
    .tickSize(5) // height of the ticks
    .tickSubdivide(true), // display ticks between text labels
    yAxis = d3.svg.axis() // generate an axis
    .scale(yRange) // set the range of the axis
    .tickSize(5) // width of the ticks
    .orient("left") // have the text labels on the left hand side
    .tickSubdivide(true); // display ticks between text labels
var transition = vis.transition().duration(1000).ease("exp-in-out");

transition.select(".x.axis").call(xAxis);
transition.select(".y.axis").call(yAxis);




vis.append("svg:g") // add a container for the axis
.attr("class", "x axis") // add some classes so we can style it
.attr("transform", "translate(0," + (HEIGHT - MARGINS.bottom) + ")") // move it into position
.call(xAxis); // finally, add the axis to the visualisation

vis.append("svg:g")
    .attr("class", "y axis")
    .attr("transform", "translate(" + (MARGINS.left) + ",0)")
    .call(yAxis);


var circles = vis.selectAll("circle").data(data)
circles.enter()
    .append("svg:circle")
    .attr("cx", function (d) {
    return xRange(d.year);
})
    .attr("cy", function (d) {
    return yRange(d.count);
})
    .style("fill", "red")

circles.transition().duration(1000)
    .attr("cx", function (d) {
    return xRange(d.year);
})
    .attr("cy", function (d) {
    return yRange(d.count);
})
    .attr("r", 10)

circles.exit()
    .transition().duration(1000)
    .attr("r", 10)
    .remove();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:21:53+00:00Added an answer on June 15, 2026 at 5:21 am

    you can also use d3.scale.category20(); to get some predefined random colors

    Just define color scale as

     var color = d3.scale.category20();
    

    Add add fill attribute to the circles as

     .attr("fill",function(d,i){return color(i);});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the link to the jsfiddle: http://jsfiddle.net/d3xMZ/ when I hover, it does exactly
Here is the link for my html http://jsfiddle.net/9rprY/18/ In this I need the middle
Please refer the fiddle http://jsfiddle.net/HCqsM/5/ Here By clicking the 'click' link for the first
for reference here is a jsfiddle link: http://jsfiddle.net/STmwz/4/ To start off with, there is
Here's a link to a jsfiddle: http://jsfiddle.net/Qt972/ When you run the fiddle you'll see
I have problem with CSS position in IE7. here is the link http://jsfiddle.net/HXcM4/30/ input,
Here's a jsFiddle link: http://jsfiddle.net/HunEj/ So you can click on the checkbox, and it'll
Here is the link http://jsfiddle.net/Cbde2/ and here are the results http://jsfiddle.net/Cbde2/embedded/result/ What I want
Here is the link: http://jsfiddle.net/LDEt6/ The first CSS rule sets the font-family as 'Helvetica
Here is the JSFiddle link: http://jsfiddle.net/stapiagutierrez/48yGU/34/ When I use padding: 10px; on the #middle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.