mpandroidchart the dot's color doesn't change in scatter chart - mpandroidchart

I'm using MPandroidchart to draw scatter chart.
I want to make a scatter chart that has a base line.
If value over the base line, in my case 0.2, its color change to red.
If not, it color is blue.
This is the codes i did.
if (d>=0.5)
{
colors.add(getBaseContext().getResources().getColor(R.color.color_red));
} else
{
colors.add(getBaseContext().getResources().getColor(R.color.color_blue));
}
value1.add(new Entry(k,d));
But it didn't change dot's color, but change squre's color next to label
I have tried
1)
if(index == specificIndex) colors.add(Color);
else colors.add(NormalColor);
2)
ArrayList<Integer> color = new ArrayList<>();
if (YOUR_CONDITION) {
color.add(ColorTemplate.rgb("#f8bf94"));
yVals1.add(new Entry(VALUE, COUNTER));
} else {
color.add(ColorTemplate.rgb("#e0e0e0"));
yVals1.add(new Entry(VALUE, COUNTER));
}
set1.setColors(color);
3)
color.add(Color.RED);
color.add(context.getResources().getColor(R.color.your_defined_color_in_colors_xml));
dataSet.setCircleColors(color);
But it didn't work.
How can i solve this?

After spending hours with this same issue, I have realized that it is the result of a bug in the MPAndroidChart project.
Basically, in the ScatterChartRenderer, the colors array is being treated such that only even colors are being applied to data points. For each Entry i, the color is set to colors[i / 2] meaning that the same color will be applied to two different entries due to integer division. This results in only half of the colors array being used.
To resolve this issue quickly, my solution was to add each entry to the DataSet twice. This means two points are drawn on top of each other, but both have the proper color set.
I am submitting a pull request to hopefully fix this issue in the next release, but for now this quick hack should work.

Related

mpandroidchart, don't draw the line when there is not data for a period of time

mpandroidchart, I am reading data from a tool every second and I am drawing that data well, but when I turn off the tool a couple of minutes and again I turn the tool on, the chart draws a consecutive line instead of leaving a space before to start again to draw the values, How can I do that using this library?
I would like to have something like the second image
I think you can't do that all you can do is when stop the data you can insert few entries with 0 value on y-axis and when resume chart will start plotting values again but you can see two lines from the last value to zero and from 0 to the next value obtained.
I finally got to draw the line Data Set as I needed,
this library is awesome, it has a bunch of functionalities.
I saw this video https://www.youtube.com/watch?v=mA3-cz8EGWo and then I realized
I can change the line color between two dots by using .setColor(List colors), so I used a map with key = data set Index and value = array of colors for that dataset, and then I just changed to transparent color where I needed
Map<Integer, List<Integer>> colorsByDataSet = new HashMap<>();
save the color every time you create an entry
addNewEntry(x,y,color,1); //1 = dataset1
if (colorsByDataSet.containsKey(1)) {
List<Integer> colors = colorsByDataSet.get(1);
colors.add(color);
colorsByDataSet.put(1, colors);
} else {
List<Integer> colors = new ArrayList<>();
colors.add(color);
colorsByDataSet.put(1, colors);
}
//identify the position where you need to change the color and then update the List<Integer>
List<Integer> colors = colorsByDataSet.get(1);
colors.set(colors.size() - 1, Color.TRANSPARENT);
colorsByDataSet.put(i, colors);
//set the new colors
((LineDataSet) set).setColors(colorsByDataSet.get(1));
this the final result
if you know about a better way I am open to hear

How to set custom colors for Odoo 12 calendar view events?

There is a good tutorial on how to achieve this in Odoo-8 here:
Tutorial , but it doesn't work on Odoo-12.
Odoo natively allows you to set a field of your model as a basis for color differentiation in calendar view.
<calendar ... color="your_model_field">
The problem is that he will decide automagically what color to assign to every value.
I need to be able to decide what color mapping to use.
Doing some diving in the web module js files, more specifically on
web/static/src/js/views/calendar/calendar_renderer.js on line 266
I found a promising function which appears to be the one responsible for deciding which color to set.
getColor: function (key) {
if (!key) {
return;
}
if (this.color_map[key]) {
return this.color_map[key];
}
// check if the key is a css color
if (typeof key === 'string' && key.match(/^((#[A-F0-9]{3})|(#[A-F0-9]{6})|((hsl|rgb)a?\(\s*(?:(\s*\d{1,3}%?\s*),?){3}(\s*,[0-9.]{1,4})?\))|)$/i)) {
return this.color_map[key] = key;
}
var index = (((_.keys(this.color_map).length + 1) * 5) % 24) + 1;
this.color_map[key] = index;
return index;
},
This function is fed the value of your field (for every calendar event) and returns the color to be used "supposedly" as background for the calendar event square.
According to the second if statement, if you manage to instantiate the CalendarRenderer class with a color_map object which has the possible values of your field as keys and color codes as values you should be ok.
According the the third if statement, if the values of your field are strings with color codes (#FFF, rgb(x, y, z) , etc) they will be set in the color_map object and returned to be used as background colors.
The last part I guess is how odoo decides on a color when no mapping is provided.
I tried both approaches with the same efect:
Image displaying the calendar view
Namely, all the calendar events are rendered with the default color taken from the fullcalendar.css stylesheet (line 529), but the color reference displays correctly on the sidebar to the right.
I would appreciate any light shed on this matter, It has to be possible to make this work!.
Thanks.

Wrap or cut long labels in Pentaho CCC

How to cut long labels of the Bar Chart Control’s base axis?
I have already tried to cut them in the Extension Points (baseAxisLabel_text):
function(a){
var str=this.scene.atoms.category.label;
if (str.length>30){
str=str.substring(0,30)+' ...';
}
return str;
}
However, it seems that Chart Control width is calculated taking into account old label length. Now I have white area at the left of my bars.
How to solve this?
I found the solution.
I just moved slightly changed function from Extension Points (baseAxisLabel_text) to baseAxisTickFormatter (Advanced Properties of the chart control)
function(v){
if (v.length>30){
v=str.substring(0,30)+' ...';
}
return v;
}

Fix series order

I am producing a graph using the following code:
var svg = dimple.newSvg("#p_m", 1200, 200+(data.f_c_c*20));
var chrt_participants = new dimple.chart(svg, data.result);
chrt_participants.setBounds(200, 50, 900, 100+(data.f_c_c*20));
var y = chrt_participants.addCategoryAxis("y", ["title", "name"]);
var x = chrt_participants.addLogAxis("x", "Activity");
var s = chrt_participants.addSeries(["cid_id","cid","action"], dimple.plot.bar);
chrt_participants.addLegend(800, 0, 400, 40, "left");
chrt_participants.draw();
It draws the following graph:
Everything is as expected, except that the series (the coloured chunks of the bars) don't seem to be put in any particular order. As you can see, for two bars, for some reason unbeknownst to me, the red value is placed before the blue.
Is there a way to fix the order of the series?
The default order is descending by value but you can easily override using series.addOrderRule(). The documentation explains how:
https://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.series#addOrderRule
On a side issue, be careful using a log axis for a stacked bar, it's very misleading. It's not immediately apparent that red and blue have about a 50/50 split of bars. You might be better using a grouped bar instead so that both categories receive comparable scaling.

Color.ToArgb relation between 5046311 and 14221235?

the form backcolor is 14221235 , but when i set the customcolor in colordialog to equal the form backcolor, it sets it to 5046311 !!! what is the problem?
this is how i am getting the background color:
get_background = Str(Abs(Form1.BackColor.ToArgb))
the reason i am turning it into a string is because i will feed it into a string which has "32498239, 234234234, 23423234, 32234432432, 423324234"
then i take this string and put it in customcolors like this. btw this piece of code works fine:
Dim numberStrings = My.Settings.mytext1.Split(","c).Select(Function(x) x.Trim())
ColorDialog1.CustomColors = numberStrings.Select(Function(x) CInt(x)).ToArray()
a user below mentioned that toargb takes into account the opacity. this is an excellent point indeed, and i want to clarify that i DO NOT need the opacity. how would i do toargb without taking into opacity?
this is what you want
Microsoft.VisualBasic.RGB(Me.BackColor.R, Me.BackColor.G, Me.BackColor.B).ToString
The 32-bit result from .ToArgb() contains not just the three visible color components (red, green and blue) but also the alpha component, which is essentially opacity. This is a pure guess on my part, but I think the ColorDialog is just used for picking RGB values, so when you set the color to the form's BackColor, the dialog just ignores the alpha component (or sets it to zero), which is why you end up getting a different number from the .ToArgb() method.
Note: this is just speculation on my part. It would help if you posted a code sample that demonstrates the specific problem.
I don't really understand the question. You want to set the custom color dialog CustomColor property to (the form's backcolor) r + g + b components? Not sure why you would do that, you can always just get the form's backcolor, set the Alpha value to 255 and then set the result to the CustomColor property:
Color c = Color.FromArgb( 255, form1.BackColor );
myColorDlg.CustomColor = c;
Or just use form1.BackColor.ToArgb() & 0xFFFFFF (if you want the integer value).
If you are asking for ARGB (A = Alpha) then you are asking for the opacity information. Instead you could use the R, G, B Properties of Color Independently.
You could use Color.FromArgb(255, me.BackColor).ToArgb() in order to get the ARGB value of the same color with 100% opacity.
To highlight how to pass the same colour (Using Fredou's answer) from a colorDialog to set a pie chart segment colour, one which is a .Net embedded chart and the other an Excel chart:
embchartPie.Series(0).Points(Index).Color = ColorDialog1.Color
With ColorDialog1.Color
xl_Pie_Chart.SeriesCollection(1).points(Index + 1).format.fill.forecolor.rgb = RGB(.R, .G, .B).ToString
End With