Hi I want to display a positive negative value graph in apex chart , I want 2 individual color like green for positive and red for negative - charts

How to display 2 bar color, attached the image.
I tried giving a loop then if the condition inside the loop but only for the first value is the color set not for the remaining values (apex chart).
colors: [function() {
for (var i in chartdata ) {
if(chartdata[i]>1){
console.log("positive")
// setPostiveColor("#0000FF")
return '#7E36AF'
} else if(chartdata[i]<0){
console.log("negative",chartdata[i])
return '#D9534F'
}
}

Related

X axis glitch Fl_charts

I have data in the form of [DateTime, num]. I have converted the DateTime object into a string and used it as a x-axis label. I am getting this glitch now. Is there a property which I need to change to fix this?
As you can see, there is a repetition of the x axis labels at either end. I am using Fl_Chart library. If you require my current code I can attach it.
fl_chart uses the interval you provide to determine which points should have labels for, however, it also creates a label for 0 and maxX. You can fix it by adding
if (value % (xAxisInterval?.ceil() ?? 1) == 0) {
//return label
}else{
return SideTitleWidget(
axisSide: meta.axisSide,
child: Container(),
);
}
to your getTitlesWidget function. Where xAxisInterval is the value you passed into your SideTitles object for interval for the xAxis.

SSRS: Custom colors for the Category axis of a stacked bar chart

I have a stacked bar chart that only ever has 5 categories(but the value of the categories change from year to year, it is a sliding 5 year window).
I have successful customised the bars to the colors I want.
But now I wish to make the label of each Category the same color as the customised bar color.
Is there a way to do this?
You can use custom code for this.
In Report Properties | Code, you can paste in the following code:
Private colourPalette As String() = {"#418CF0", "#FCB441", "#DF3A02", "#056492", "#BFBFBF", "#1A3B69", "#FFE382", "#129CDD", "#CA6B4B", "#005CDB", "#F3D288", "#506381", "#F1B9A8", "#E0830A", "#7893BE"}
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()
Public Function GetColour(ByVal groupingValue As String) As String
If mapping.ContainsKey(groupingValue) Then
Return mapping(groupingValue)
End If
Dim c As String = colourPalette(count Mod colourPalette.Length)
count = count + 1
mapping.Add(groupingValue, c)
Return c
End Function
This will give you the option of the pastel colour palette. If you want other colours, simply replace the hex colour codes with values of your choice.
To use this, simply use the following expression:
=Code.GetColour(Fields!Thingy.Value)
Use this on your series and your label fill expressions. This will ensure that the same colour appears for both. If you have multiple graphs with the same values in, this will also ensure that the same data series across multiple graphs always have the same colour.

Unity is returning material color slightly wrong

I have this mini task in my game where you need to click trophies to change color of the wood on them. I have two arrays of colors, one is an array containing all possible colors and the other one contains four colors (the answer) as follows:
I've double checked that the colors are equal between the two arrays. For example the purple in Colors-array has exactly the same r, g, b & a values as the purple in the Right Order-array.
To check whether the trophies has correct color I just loop through them and grab their material color. Then I check that color against the Right Order-array but it's not quite working. For example when my first trophy is purple it should be correct, but it's not because for some reason Unity is returning slightly different material color than excepted:
Hope somebody knows why this is happening.
When you say, they are exactly same color, I assume you are referring rgb values from Color Inspector, which are not precise values.
Now I dont know what could be causing in different values of colors but
You can write an extension method to compare the values after rounding them to closest integer.
public static class Extensions
{
public static bool CompareRGB(this Color thisColor, Color otherColor)
{
return
Mathf.RoundToInt(thisColor.r * 255) == Mathf.RoundToInt(otherColor.r * 255) &&
Mathf.RoundToInt(thisColor.b * 255) == Mathf.RoundToInt(otherColor.b * 255) &&
Mathf.RoundToInt(thisColor.g * 255) == Mathf.RoundToInt(otherColor.g * 255);
}
}
usage:
Color red = Color.Red;
red.CompareRGB(Color.Red); // true;
red.CompareRGB(Color.Green); // false;
Hope this helps.
I would use a palette. This is simply an array of all the possible colors you use (sounds like you have this). Record, for each "trophy", the INDEX into this array, at the same time you assign the color to the renderer. Also, record the index for each "button", at the same time you assign the color to the renderer.
Then you can simply compare the palette index values (simple integers) to see if the color matches.

MpChartLib in Android - hide text in small slices of PieChart

How can i hide text of small slices in pie chart without to remove the text from the legend in the bottom?
I tried to remove the text like this:
if ((yVal < 5F) {
name = "";
} else {
//Add to y values
}
But then the legent text is empty also. so the users can't really know who is this slice.
My solution is to separate the legend texts and the pie chart slices text.
I set the legend (bottom map for each color) text and colors in this way
- In loop for all the contacts:
List<Integer> colors = new ArrayList<>();
List<String> labels = new ArrayList<>();
labels.add(fullName);
colors.add(METRIC_COLORS[index]);
Legend l = chart.getLegend();
l.setCustom(colors, labels);
In addition I added the text of pie-slices:
PieDataSet dataSet = new PieDataSet(yVals1, "");
dataSet.setColors(METRIC_COLORS);
I have a situation like this:
for (PieEntry pieEntry : leastPieEntries){
if(pieEntry.getValue() < 10)
{
pieEntry.setLabel("");
}
}
Tried to loop through all PieEntries but getValue returns the float value instead of percentage value...how did you do it?

Is it possible to make colors invisible in the code?

For a game that I am currently making, I have a black background with many white dots, which are being used to represent stars. I have no need for the black color however, and I only wish for the stars to show. My question is this: Is it possible to completely hide the black color without using an image manipulation program, that is, using only code? Any help is appreciated.
This is the form:
// some rgba color representation
struct t_rgba {
uint8_t r, g, b, a;
};
bool SetToTransparentIfPixelIsBlack(t_rgba* const rgba) {
// is it black?
if (0 == rgba->r && 0 == rgba->g && 0 == rgba->b) {
// then set the alpha value to transparent:
rgba->a = 0;
}
}
although the image data you are using will be represented differently.