alteration of colors in a Chartist chart

Currently, I am working with a chartist graph where the colors are defined at a framework level. However, I need to make changes to the colors for a specific graph without altering the framework level settings. I attempted to create a .less file, but unfortunately, the changes are not being reflected.

Are there any alternative methods to adjust the color of a bar graph? Also, if I add more bars, I would like the colors to be different for each.

For reference, the link to the framework changes for chartist can be found here.

The color changes need to be made in the file located at here.

I have included a snippet of code in the .less file, but the changes are not showing up. Any suggestions or tips would be greatly appreciated.

 .ct-series-a .ct-bar {
  stroke: white;
  stroke-width: 20px;
}
.ct-series-b .ct-bar {
      stroke: blue;
      stroke-width: 20px;
    }

Thank you.

Answer №1

Even though this response is a bit delayed, I wanted to share a helpful Java script solution that I came across on this website. The solution demonstrates how you can dynamically color various components.

let chart = new Chartist.Bar('#barChart', data, options, responsiveOptions);
    chart.on('draw', function(context) {


      if(context.type === 'bar') {
         context.element.attr({
          style: 'stroke:  red'
        });
      }else if(context.type === 'point') {
            context.element.attr({
            style: 'stroke:  blue'
        });
      }else if(context.type === 'line') {
          context.element.attr({
            style: 'stroke:  green'
        });
      }
    });

Answer №2

I have recently established separate CSS (LESS) styles for each individual chart component.

.sales-chart {
    .ct-series-a {
        .ct-area {
            fill: #F14A78;
        }

        .ct-bar, .ct-line, .ct-point, .ct-slice-donut {
            stroke: #F14A78;
        }
    }

    .ct-series-b {
        .ct-area {
            fill: #65C6F9;
        }

        .ct-bar, .ct-line, .ct-point, .ct-slice-donut {
            stroke: #65C6F9;
            /*stroke-dasharray: 5px;*/
        }
    }

    .ct-series-c {
        .ct-area {
            fill: #FFA500;
        }

        .ct-bar, .ct-line, .ct-point, .ct-slice-donut {
            stroke: #FFA500;
        }
    }
}

Answer №3

Less files require compilation into CSS as they are not directly CSS. Find a suitable compiler on GitHub or visit lesscss.org for more options.

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

The function is not explicitly declared within the instance, yet it is being cited during the rendering process in a .vue

import PageNav from '@/components/PageNav.vue'; import PageFooter from '@/components/PageFooter.vue'; export default { name: 'Groups', components: { PageNav, PageFooter, }, data() { return { groups: ...

Utilizing an array of labels and values to link select and ng-options for binding

Struggling to set both the label and value of a select element using an array Have an array containing countries $scope.countries = [ {abbr:"US", name:"United States"}, {abbr:"CA", name:"Canada"},...... ] Desiring the select element output as f ...

Displaying information from four different arrays in a column using ng-repeat

There are 4 arrays filled with dynamic data that I want to display in a vertical table. Currently, my code looks like this: https://i.sstatic.net/aQLSg.png This is the snippet of my code: <table class="table table-striped"> <tbody> ...

Taking out the z-index from the transition code

Is there a way to restructure the code without needing to use z-index for the transition? Without z-index: https://jsfiddle.net/Legcb42d/ .container1 { position: relative; width: 100%; height: 100%; } .container1.slide { height: auto; min-heigh ...

Avoid opening the page when attempting to log in with jquery, ajax, and php

I am facing an issue with my code. I have a file named "index.html" which contains a login form. Another file called "dash.js" retrieves the username and password from the login form and redirects to "connectdb.php" to check the login credentials with the ...

Stay tuned for updates on elements being loaded into a div from an external source

I have a project in progress that involves integrating HTML and JQuery. One of the tasks is to replace a div with a new one from an external HTML file using the load('some.html #someDiv') method. Everything was going smoothly until I tried to li ...

Testing the Angular service call in a unit test using karma and jasmine

I encountered an error stating service undefined when attempting to run a unit test for a service call in my application. Despite spending considerable time trying to pinpoint the issue, I have been unsuccessful in isolating its origin. Any assistance in r ...

The justify-content-around property in Bootstrap-4 does not seem to be functioning as expected when

I've been working with bootstrap-4 and I'm struggling to understand why justify-content-around functions properly with flex-row but not with flex-column. I tried applying flex-column justify-content-around to div.item2 but it's not producing ...

Alignment of headers and footers in email newsletters for various email clients<td>

With my limited coding skills, I've been struggling to keep the header and footer aligned properly in all email clients. The footer consistently displays a 1 px gap between elements, which causes it to move around unpredictably. Here's the full s ...

Actions cannot be performed on elements generated by ng-repeat

I am facing a challenge where I need to display a list of languages on a page, allowing users to change their selections based on previous choices. To achieve this functionality, I have written the following code snippet: ... <tbody> & ...

The dividers flicker in and out of view

I have a menu with 7 elements, where clicking on an element causes its content to appear by fading in. If another element is clicked, the current content fades out and the new content fades in. I've successfully implemented this concept for 3 of the 7 ...

How can elements be displayed differently depending on the return value of a function?

Basically, I am looking to display different content based on the status of a job: Show 'Something1' when the job is not processing Show 'Something2' when the job is running and has a status of '0' Show 'Something3&apos ...

Angular code causing an unexpected blank page to be printed again

Trying to display the content of my HTML page is proving to be a challenge. I've been utilizing angularPrint, but an issue persists in the form of a second blank page appearing in the preview alongside the actual content. Eliminating this unwanted sec ...

Discovering the method to access a file without the standard .html or .php extension on the local host at 127.0.0

Is there a way to access my file without the .html or .php extension? My folder structure looks like this: C:\Apache24\htdocs\search-html\test search-html test low.html high.html ...

What is the solution to prevent the inadvertent activation of onmouseEnter when onmouseLeave

I recently created a CSS/Jquery script that enlarges a DIV and replaces a font awesome icon with some text when hovered over, then changes it back to the icon when the mouse leaves. However, I noticed in the console that when I remove the mouse from the DI ...

The arrangement vanishes when using identical html/css coding

When using the same HTML/CSS coding, the layout disappears and appears misaligned on one page but works perfectly on another. The issue seems to be that the first section of the main area is getting a width of 938px instead of 5px. I've tried adding w ...

Sending emails to multiple groups in Opencart can be easily achieved with the

I am interested in customizing Opencart's admin panel to allow for the selection of multiple customer groups when sending emails. However, I am unsure of where and how to make these modifications as I am relatively new to this type of task. https://i ...

What is the best way to combine two arrays into a single array using AngularJS?

Here is a code snippet: $scope.studentDetails=[]; $scope.studentDetails=[0][id:101,name:one] [1][id:102,name:two] [2][id:103,name:three] $scope.studentMarks=[]; $scope.studentMarks=[0][id:101,marks:78] ...

The camera continues to move smoothly after the static-body effect has been activated

I recently implemented A-Frame physics using this library, and encountered an issue where applying static-body to the a-mixin voxel in the Minecraft demo still allowed my character to move through the box. My camera is configured with universal-controls f ...

Stopping Angular.js $http requests within a bind() event

As stated in this GitHub issue Is it expected to work like this? el.bind('keyup', function() { var canceler = $q.defer(); $http.post('/api', data, {timeout: canceler.promise}).success(success); canceler.resolve(); } ...