Enhancing Charts with Icon Images on the Y-Axis Using Britechart

Currently, I am utilizing Vue with Britecharts to create a horizontal bar chart. My goal is to integrate avatar images on the y-axis beside the name label. After conducting some research, I came across helpful resources such as D3 How to place image next to horizontal line text and this which demonstrate the desired outcome using D3.

I am seeking guidance on how to achieve this functionality within Britecharts. Below is a snippet of my code in action.

Codepen: https://codepen.io/cooltaiwanesesam/pen/RwPYpbz

createHorizontalBarChart() {
    let barChart = new britecharts.bar(),
        margin = {left: 120, right: 20, top: 20, bottom: 30},
        barContainer = d3.select('.js-horizontal-bar-chart-container'),
        containerWidth = barContainer.node() ? barContainer.node().getBoundingClientRect().width : false;

    barChart
       .isHorizontal(true)
       .margin(margin)
       .width(containerWidth)
       .colorSchema(britecharts.colors.colorSchemas.britecharts)
       .valueLabel('percentage')
       .height(300);

    barContainer.datum(this.data.reverse()).call(barChart); 
}

Answer №1

Resolved the issue and sharing the code to assist those in need.

View the code here

barChart
  .isHorizontal(true)
  .width(containerWidth)
  .height(300);

barContainer.datum(dataset).call(barChart);

d3.selectAll('.y-axis-group .tick')
  .each((d, i, list) => {        
    let img = barData.data.find((item) => item.name === d).img;

    d3.select(list[i])
      .append('image')
      .attr('x', -36)
      .attr('y', -22)
      .attr('width', 42)
      .attr('height', 42)
      .attr('xlink:href', img)
  });

For more information, visit: Eventbrite Britecharts Issue 798 Special thanks to Marcos from Britecharts.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the Checkbox id of a material-ui checkbox by accessing the object

I'm currently working on extracting the id of a Checkbox object in my JSX code. Here's how I've set it up: <div style={{display: 'inline-block', }}><Checkbox id='q1' onclick={toggleField(this)}/></div> ...

Is there a RxJS equivalent of tap that disregards notification type?

Typically, a tap pipe is used for side effects like logging. In this scenario, the goal is simply to set the isLoading property to false. However, it's important that this action occurs regardless of whether the notification type is next or error. Thi ...

Mastering the art of using res.send() in Node.js

I have been working on a project using the mongoose API with Node.js/Express. There seems to be an issue with my get request on the client side as the data is not coming through. Can someone help me figure out what's wrong? Snippet of backend app.ge ...

Babel continues to encounter issues with async/await syntax, even with all the necessary presets and plugins installed

I am encountering a compiler error while attempting to compile an async/await function using Babel. Below is the function in question: async function login(username, password) { try { const response = await request .post("/api/login") . ...

Arranging elements in HTML for Manipulating with JavaScript

I haven't started coding yet, but I'm contemplating the overall strategy. My front end is primarily composed of HTML tables, giving it an Excel-like appearance. I am considering generating default pages and then using JavaScript to dynamically m ...

Encountered a Vue.js Vuex error: "Unable to dispatch function in context."

I have implemented a stopwatch function that can run the stopwatch as shown below : Stopwatch.vue <script> export default { data() { return { time: "00:00.000", timeBegan: null, timeStopped: null, stoppedDurat ...

Can you explain the process of initiating a script?

Seeking Answers: 1) When it comes to initializing a script, is there specific code placement in the js file or do you need to create initialization code from scratch? 2) What sets jQuery apart from other scripts that require activation - why does jQuery. ...

Can I identify the gender of visitors to my blogger.com website?

Is there a way to customize content based on the gender of the visitor using JavaScript or other methods like an AJAX call to an external server with Python/Ruby backend for GData APIs access, or by retrieving cookie information? Google, for instance, ca ...

Scripting issues detected in Safari and Microsoft Edge browsers

I recently finished developing an AngularJs Application that works flawlessly on Google Chrome and Mozilla Firefox. However, upon testing it on Safari and IE-11, I encountered errors in the console. One particular piece of code that causes issues is used ...

Uncertainty arises from the information transmitted from the controller to the Ajax function

In one of my coffee scripts, I have an AJAX call that calls a method in a controller. The AJAX call is structured like this: auto = -> $.ajax url : '<method_name>' type : 'POST' data : <variable_name> ...

Using AngularJS, trigger an httpget request when the value in a textbox is changed

I am currently working on a web service that returns a json file when called with an entry ID parameter. I have successfully created an Angular method to retrieve the data from this service. However, I am facing difficulty in recalling the service when the ...

Scale up the font size for all text on the website uniformly

Recently, I decided to switch a website's font to a non-web typeface. However, I quickly realized that the font was extremely thin and difficult to read. I attempted a simple CSS fix using * { font-size:125% }, but unfortunately, it did not have the d ...

Error: Trying to access the 'commit' property of an undefined variable in Angular

I am currently working on a project that involves Angular and Spring Boot integration. The project retrieves parameters from the Spring Boot back-end through a DTO, and I display this information on the front-end screen. However, upon showing the dialog co ...

Adjusting Bootstrap card content on hover

Currently, I am in the process of developing a website that features a list of products presented in bootstrap cards. I am seeking advice on how to dynamically change the text displayed on these cards when a user hovers over them. Specifically, I want to ...

There seems to be an issue with the bullet functionality in phaser.io

I'm having trouble firing a bullet from my object in my game. I have been struggling to find the proper reason for the issue. Here is a snippet of my code. Game.js var Game = { preload : function() { // spaceship image screen th ...

Keep the HTML structure of an element in the DOM while excluding it from an ng-repeat loop

I am currently working with the array badge = [{'name':'abc', 'flag': true}, {'name':'cde', 'flag': false}, {'name':'def', 'flag': true} ] After using it with ng-rep ...

Error TS2403: All variable declarations following the initial declaration must be of the same type in a React project

While developing my application using Reactjs, I encountered an error upon running it. The error message states: Subsequent variable declarations must have the same type. Variable 'WebGL2RenderingContext' must be of type '{ new (): WebGL2 ...

Tips for refreshing the page upon Geolocation request

I am working on a HTML5 project that requests geolocation from the user. Here is an image of what it looks like: https://i.sstatic.net/o6yCj.png My main query is: Is there a way to refresh the page automatically once the user grants permission to share t ...

What is the best way to show nested objects in JavaScript?

let paragraph = document.createElement('p'); document.body.appendChild(paragraph) const fruit = { type: 'Apple', properties: { color: 'Green', price: { bulk: '$3/kg', smallQty: '$4/kg' ...

Injecting components into the DOM using JavaScript in Vue.js

I am currently developing a GUI for a webgame using Vue.JS and opting to use http-vue-loader instead of Webpack or similar tools. Personally, I find them cumbersome and prefer to avoid using them. Typically, in order to integrate my components into the DO ...