Trying to create a stacked bar - stacked-chart

Here are my codes:
a=df['Case Status'].value_counts()
a.plot(kind = 'bar', stacked = True)
Results
Closed 13
Notified 9
Name: Case Status, dtype: int64
I would like the bars to be stacked. May I know how do I achieve that?

Related

trying to identify one bar to the left and one bar to right of a selected bar using input.time in pinescript

hoping someone can help me with what should be simple but I can't seem to find a solution.
Using input.time/confirm=true, i select a bar on the chart
I would like to print a label on the selected bar, on the bar to the left and on the bar to the right.
The issue I think is that input.time is not compatible with a simple +/-1 so I think it needs to be converted to a bar index. I've tried doing that in the code below but it still doesnt seem to work
The reason for creating this code is to ultimately get the system to determine if the selected bar is a pivot and then based on that do other things. This was just the first step so I can understand what I'm doing wrong.
Any assistance appreciated!
//#version=5
indicator("My script", overlay = true)
start_time = input.time(timestamp("20 Jan 2021"), "Start Calculation", confirm=true)
start_bar = bar_index[start_time]
// Add label above the selected bar
label.new(x=start_time, y=high[start_bar], text='Selected bar', color=color.white, xloc=xloc.bar_time, yloc=yloc.abovebar)
// Add label above the bar to the left of the selected bar
label.new(x=time[start_bar-1], y=high[start_bar-1], text='Bar left', color=color.white, xloc=xloc.bar_time, yloc=yloc.abovebar)
// Add label above the bar to the right of the selected bar
label.new(x=time[start_bar+1], y=high[start_bar+1], text='Bar right', color=color.white, xloc=xloc.bar_time, yloc=yloc.abovebar)
using this code the selected bar correctly display's its label - but the left and right bars are completely off ...
enter image description here
Like this:
//#version=5
indicator("My script", overlay = false)
start_time = input.time(timestamp("8 Jan 2023"), "Start Calculation", confirm=true)
var int barStart = 0
if time == start_time
barStart := bar_index
if barStart
var l1 = label.new(x=barStart, y=high, text='Selected bar', color=color.white)
// Add label above the bar to the left of the selected bar
var l2 = label.new(x=barStart-1, y=high, text='Bar left', color=color.white)
// Add label above the bar to the right of the selected bar
var l3 = label.new(x=barStart+1, y=high, text='Bar right', color=color.white)
If you need time coordinate, then you can use timeframe.in_seconds() with current chart's timeframe, and then add resulted value to the start_time, so it will be +1 bar.

Ruby axlsx pie chart title font size

I'm using the axslx ruby gem to create a spreadsheet with a pie chart. For the most part it is very straightforward and I've had no problems with one exception: I can't figure out how to set the font size for the title in the pie chart. I've read through the documentation and examples and found no mention of it. I'm sure I have overlooked it but if anyone knows how to do that, I would appreciate any help.
thanks!
adding code ... sorry, should have provided this initially
issue_sheet.add_chart(Axlsx::Pie3DChart, start_at: 'I3', end_at: 'S32') do |chart|
chart.add_series data: issue_sheet['G3:G7'], labels: issue_sheet['F3:F7'], colors: ['9467BD','D62828','EF7E12','82BBDD','3AA02B']
chart.title = "Distribution by Severity"
chart.d_lbls.show_val = false
chart.d_lbls.show_percent = true
chart.d_lbls.d_lbl_pos = :outEnd
chart.d_lbls.show_leader_lines = true
end
I did notice something interesting but I'm not sure what it means. If I use a cell reference rather than a string for the chart.title, the font size changes.
chart.title = "Distribution by Severity" # this sets the font size to 16
chart.title = issue_chart['F2'] # this sets the font size to 10
You can make use of sz property provided in this link
item_style = s.add_style :b => false, :sz => 9, :font_name => 'courier'
row = sheet.add_row [item.name, item.price], :style => item_style

Dynamically change background colour of a Dashing widget

I've built a dashboard using the ruby based Dashing framework and all seems to be running well but I'd like to be able to change the background colour of one of my List widgets (mywidget) based on one of the values in the list.
My updatelist.rb job file currently looks like:
hashdata = Hash.new({ value: 0 })
SCHEDULER.every '10s' do
File.open('xxx.txt').each do |line|
field = line.split(;).first
value = line.split(;).last
if ['Status', 'Active', 'Duration].include? field
hashdata[field] = { label: field, value: value }
end
end
send_event('mywidget', { items: hashdata.values })
end
The file it is reading (xxx.txt) is formatted like:
Status; Good
Active; No
Duration; 1000
I'd like change the background colour of the list widget based on the value of Status i.e. Good=green, Average=yellow, Poor=red.
How can I do this? Adding something to the coffee script seems the obvious solution but I can't see how to achieve it
You are correct about needing code in the coffeescript. I suggest something like the following:
class Dashing.List extends Dashing.List
color: () ->
data = #get('items')
status = # code to process color from your data (I'm not sure exactly your format)
switch status
when "Good" then "#33cc33" # green
when "Average" then "#ffff00" # yellow
when "Poor" then "#ff0000" # red
else "#000000"
onData: (data) ->
# change the background color every time that new data is sent
$(#get('node')).css 'background-color', #color()

random images in corona sdk

I have 3 images and 1 button -
I want to be able to click my button and have 1 of the 3 images appear. And everytime I click the button i want a new random image to appear in the place of the last image......Pretty simple it would seem, but Im losing hair over this and am about to call it quits......Can anyone help me do this? I want to learn, so please comment the code if you decide to help me....Thanks in advance.
So far, I have:
display.setStatusBar( display.HiddenStatusBar ) -- hide status bar
--insert background
local bgImg = display.newImageRect( "images/myBG.jpg", 625, 450 )
bgImg.x = display.contentCenterX -- center bg on X
bgImg.y = display.contentCenterY -- center bg on Y
-- scripture references
myTable = {
display.newImage("images/btnLogo1.png"),
display.newImage("images/btnLogo2.png"),
display.newImage("images/btnLogo3.png"),
}
randomPicture = myTable[math.random(1,3)]
This should work:
-- scripture references
myTable = {
"images/btnLogo1.png",
"images/btnLogo2.png",
"images/btnLogo3.png",
}
local randomPicture = myTable[math.random(1,3)]
display.newImage(myTable[randomPicture])
I hope you need no explanation about it :)
If your image names are continous, that is like img_1,img_2,img_3. etc... then you can use the following method:
-- Display an image
local myImage = display.newImageRect("images/btnLogo1.png",50,50)
myImage.x = display.contentWidth/2
myImage.y = display.contentHeight/2
-- Call this function on button click
function imageChangeFunction()
-- remove the previous image
if(myImage)then myImage:removeSelf() end
-- creating the sprite with new image
myImage = display.newImageRect("images/btnLogo"..math.random(3)..".png",50,50)
myImage.x = display.contentWidth/2
myImage.y = display.contentHeight/2
print("Image changed...")
end
-- Here I am assigning the listener to Runtime, you can change it for your button
Runtime:addEventListener("tap",imageChangeFunction)
Note:
math.random(3) gives you any random number between 1 and 3.
.. is used for concatenation. So, "images/btnLogo"..math.random(3)..".png" will give you any of the following strings:
images/btnLogo1.png
images/btnLogo2.png
images/btnLogo3.png
For more info, visit: math.random() and Corona String Operations

Stacked Bar - Gruff Graph

I need to generate a Stacked Bar Graph using Gruff. I have tried with the following code:
require 'rubygems'
require 'gruff'
g = Gruff::StackedBar.new('450x450')
g.sort = false
g.maximum_value = 100
g.minimum_value = 0
g.y_axis_increment = 10
g.title = 'Quarterly Exams'
g.data('English',20,30,40)
g.data('Maths',10,20,30)
g.sort = false
g.write('quarterly_progress.png')
But, this throws an error saying wrong number of arguments. I want a stacked bar graph with showing three values.
Just put values inside aray like this:
g.data('English',[20,30,40])
g.data('Maths', [10,20,30])
See gruff documentation on rubyforge: http://gruff.rubyforge.org/. Gruff::Base#data

Resources