question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change Color settings (stroke) dynamically; depends on value

See original GitHub issue

Hi,

I’m not very fimilar with javascript and I searched for a solution the last few days. Perhaps it’s very easy (it seems so) but I didn’t get it.

I have a bar chart and wan’t to have red for negativ values (< 0) and green for the other ones ( > = 0). The circles should have the same color as the bars. That’s my code:

var Chartist3 = new Chartist.Bar('#chart3', { labels: [], series: [ myDatalast10 ] }, { height: 240, fullWidth: true, showGrid: true, showLabel: true, axisY: { onlyInteger: true, offset: 20 }, axisX: { labelInterpolationFnc: function(value, index) { return index % 2 === 0 ? value : null; } }, plugins: [ Chartist.plugins.tooltip() ] }); Chartist3.on('draw', function(data) { if(data.type === 'bar') { data.group.append(new Chartist.Svg('circle', { cx: data.x2, cy: data.y2, r: Math.abs(Chartist.getMultiValue(data.value)) * 1.2 + 2.5 }, 'ct-slice-pie')); } });

And that’s my actual chart:

image

Perhaps anybody have a solution for me.

Thanks and greets Maurice

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
emcdngcommented, May 15, 2017

You can move your circle code snippet into the upper logic…

1reaction
emcdngcommented, May 15, 2017
                var red= '#ff0000';

                chart.on('draw', function (context) {
                        if (context.type === "bar") {
                            if (context.value.y < 0) {
                                context.element.attr({
                                   style: 'stroke: ' + red + '; fill: ' + red + ';'
                                });
                            } 
                        }
                    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Changing stroke color dynamically
Look at this question: InkCanvas Eraser. In the MSDN it states: If you change the EraserShape, the cursor rendered on the InkCanvas is...
Read more >
Photoshop Brushes - Color Dynamics
Learn how to dynamically control the hue, saturation and brightness of your brushes as you paint using the Color Dynamics options.
Read more >
How do I dynamically change the color and size of ...
Documentation / FAQ / The graph viewer. How do I dynamically change the color and size of elements in the viewer ? You...
Read more >
Applying styles and colors - Web APIs | MDN
Assigning transparent colors to stroke and fill style ctx. ... that this behavior depends on the current lineCap style whose default value ......
Read more >
Dynamically change colour depending on dropdown
Hi All,. we are trying to create a custom block that changes of output type and of colour whenever we change the dropdown...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found