How to change color in a column in lazyhighcharts? - ruby-on-rails-3

I am using LazyHighCharts in rails 3. My requirement is to show different color in a column.
when i use
series = {
:type=> 'bar',
:name=> [],
:data=> #rooms,
:color=> 'pink'
}
it displays whole column in pink color. Suppose i have 5 rows in a column and i want to show first row in pink color and the rest four row in green color. can anyone suggest me solution for this.
thnks

i don't know if you have resolved this issue, but this is how i resolved it.
#Controller before set data to the series option
data = []
your_array.each do |t|
data << {:y=>t.value, :color=>"#"+("%06x" % (rand * 0xffffff))}
end
then set data to series option
f.series({:name=>"Subcurso", :data=>data} )

Related

R tableGrob cell colors with condition on multiple columns

Is there a way to put colors on all the cells of a tableGrob that are not 0 ?
I have this table with a lot of lines
[][1]
[1]: https://i.stack.imgur.com/w7RCJ.png
I am using tableGrob and then grid.arrange to put 2 tables on the same page with some text
tab1<-tableGrob(tab_glob,rows=NULL,theme = ttheme_default(10),widths=unit(rep(1/ncol(tab_glob), ncol(tab_glob)), "null"), heights=unit(rep(0.95/nrow(tab_glob), nrow(tab_glob)),"npc"))
tab2<-tableGrob(Notes_tous,rows=NULL,theme = ttheme_default(11))
footnote<- textGrob("Moyenne référence = résultats techniciens référents")
padding<-unit(0.5,"line")
tab3<-gtable_add_rows(tab2,
heights = grobHeight(footnote)+ padding,pos=0)
tab3 <- gtable_add_grob(tab3,list(footnote),
t=1, l=1,
r=ncol(tab2))
pdf(paste("Table_",i,".pdf",sep = ""),width=10,height=15) #save in pdf
Point_tab<-grid.arrange(tab1,tab3,ncol=1,nrow=2, top=textGrob("\n \n \nNombre de pointages par note",gp=gpar(fontsize=14,font=3)))
dev.off()
In the first table, showing all the values, I am looking for a way to highlight the values that are not 0 in all the columns. All the answers I have found on the internet are for particular cells or a particular value... Do you have any idea to help me update my code ?
Kind regards,

How do you update the formatting of a cell using xlsxwriter?

I am generating an excel file from Python using XlsxWriter.
I'm trying to "layer" formatting depending on the cell value. In pseudocode:
for rowId in rows:
for colId in cols:
value = table.loc[rowId, colId]
if value < 0:
# Make font red
for rowId in rows:
for colId in cols:
value = table.loc[rowId, colId]
if value > 1e6:
# Make bg orange
for rowId in rows:
for colId in cols:
value = table.loc[rowId, colId]
if value is False:
# Make bg purple
In practice I'm finding it hard to layer formatting without either creating a format object for each combination of attributes, or creating a format object per cell.
Any ideas of how this could be achieved?

What is the cleanest way to create a new column based on a conditional of an existing column?

In pandas I currently have a data frame containing a column of strings: {Urban, Suburban, Rural}. The column I would like to create is conditional of the first column (i.e. Urban, Suburban, Rural are associated with the corresponding colors) {Coral, Skyblue, Gold}
I tried copying the first column and then using .replace but my new column seems to return NaN values now instead of the colors.
new_column = merge_table["type"]
merge_table["color"] = new_column
color_df = merge_table["color"].replace({'Urban': 'Coral', 'Suburban': 'Skyblue', 'Rural': 'Gold'})
data = pd.DataFrame({'City Type': type,
'Bubble Color': color_df
})
data.head()
You can do
merge_table['New col']=merge_table["color"].replace({'Urban': 'Coral', 'Suburban': 'Skyblue', 'Rural': 'Gold'})
Okay. in the future, its worth typing the codes using 'Code Samples' so that we can view your code easier.
Lots of areas can improve your code. Firstly you do the entire thing in one line:
merge_table["color"] = merge_table["type"].map(mapping_dictionary)
Series.map() is around 4 times faster than Series.replace() for your information.
also other tips:
never use type as a variable name, use something more specific like city_type. type is already a standard built-in method
data = pd.DataFrame({'City Type': city_type, 'Bubble Color': color_df})
if make a copy of a column, use:
a_series = df['column_name'].copy()

Bar and Line charts are not synced when in the same chart area

I have problem with a chart in vb.net. The problem is that line and bar are not synced in the chart area. I've attached a picture to make it clear what I mean
Here is the code where I populate the chart. I´m getting the data from a database.
Dim theDate As Date
For i As Integer = Count - 1 To 0 Step -1
'Chart1.Series("serRxTime").Points.AddY(dv(i)(0) / 60)
theDate = dv(i)(1)
Chart1.Series("serTime").Points.AddXY(theDate.ToString("dd-MMM HH:MM", enUS), dv(i)(0) / 60)
Chart1.Series("serAdd").Points.AddY(dv(i)(2))
Next
Line and column series have the same XValues that's why their centres are aligned. You would need to generate different XValues for the two series. XValues that are offset by a small margin. Something like this:
Chart1.Series("serTime").XValues = {0.8, 1.8, 2.8, 3.8,,...,count - 0.2}
Chart1.Series("serAdd").XValues = {1, 2, 3, 4,..., count}
I used 0.2 difference, but this will be different in your case (especially since it seems you have date axis set?). This would push the line series to the left.
I created an example for you. On the first picture you can see the data for the columns. Their x values are 1,2,3,4,...,12 and their y values are marked with blue.
And this is the values for the XY chart. As you can see I moved the x values by 0.2 to the left.

Matplotlib table: individual column width

Is there a way to specify the width of individual columns in a matplotlib table?
The first column in my table contains just 2-3 digit IDs, and I'd like this column to be smaller than the others, but I can't seem to get it to work.
Let's say I have a table like this:
import matplotlib.pyplot as plt
fig = plt.figure()
table_ax = fig.add_subplot(1,1,1)
table_content = [["1", "Daisy", "ill"],
["2", "Topsy", "healthy"]]
table_header = ('ID', 'Name','Status')
the_table = table_ax.table(cellText=table_content, loc='center', colLabels=table_header, cellLoc='left')
fig.show()
(Never mind the weird cropping, it doesn't happen in my real table.)
What I've tried is this:
prop = the_table.properties()
cells = prop['child_artists']
for cell in cells:
text = cell.get_text()
if text == "ID":
cell.set_width(0.1)
else:
try:
int(text)
cell.set_width(0.1)
except TypeError:
pass
The above code seems to have zero effect - the columns are still all equally wide. (cell.get_width() returns 0.3333333333, so I would think that width is indeed cell-width... so what am I doing wrong?
Any help would be appreciated!
I've been searching the web over and over again looking for similar probelm sollutions. I've found some answers and used them, but I didn't find them quite straight forward. By chance I just found the table method get_celld when simply trying different table methods.
By using it you get a dictionary where the keys are tuples corresponding to table coordinates in terms of cell position. So by writing
cellDict=the_table.get_celld()
cellDict[(0,0)].set_width(0.1)
you will simply adress the upper left cell. Now looping over rows or columns will be fairly easy.
A bit late answer, but hopefully others may be helped.
Just for completion. The column header starts with (0,0) ... (0, n-1). The row header starts with (1,-1) ... (n,-1).
---------------------------------------------
| ColumnHeader (0,0) | ColumnHeader (0,1) |
---------------------------------------------
rowHeader (1,-1) | Value (1,0) | Value (1,1) |
--------------------------------------------
rowHeader (2,-1) | Value (2,0) | Value (2,1) |
--------------------------------------------
The code:
for key, cell in the_table.get_celld().items():
print (str(key[0])+", "+ str(key[1])+"\t"+str(cell.get_text()))
Condition text=="ID" is always False, since cell.get_text() returns a Text object rather than a string:
for cell in cells:
text = cell.get_text()
print text, text=="ID" # <==== here
if text == "ID":
cell.set_width(0.1)
else:
try:
int(text)
cell.set_width(0.1)
except TypeError:
pass
On the other hand, addressing the cells directly works: try cells[0].set_width(0.5).
EDIT: Text objects have an attribute get_text() themselves, so getting down to a string of a cell can be done like this:
text = cell.get_text().get_text() # yup, looks weird
if text == "ID":