I am drawing a Trend chart(line) but in my case the legend Text is really big so it there any way that I can word wrap the text.
I think you can use the string functions that you can find in this link to manipulate the titles of series and try to reduce their length. I have made a suggestion code that I think can help you achieve as you want:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scLine
TChart1.AddSeries scLine
Dim i As Integer
TChart1.Series(0).AddXY 0, 30, "", clTeeColor
TChart1.Series(0).AddXY 10, 100, "", clTeeColor
TChart1.Series(1).AddXY 0, 50, "", clTeeColor
TChart1.Series(1).AddXY 50, 120, "", clTeeColor
TChart1.Series(0).Title = "DDDDAAAAFFFFLLLLRRRRSSSS"
TChart1.Series(1).Title = "AAAALLLLSSSSTTTTEEEERRRR"
SeriesTitleWarp TChart1.SeriesCount
End Sub
Private Sub SeriesTitleWarp(ByVal count As Long)
'Replace some chars of string title to ...
Dim i As Integer
For i = 0 To count - 1
'Calculate the size of string
Dim LenString As Integer
LenString = Len(TChart1.Series(i).Title)
'First replace the Left chars for ...
Dim TitleString As String
TitleString = TChart1.Series(i).Title
Mid$(TitleString, 10, 3) = "..."
'After cut the string
TitleString = Left(TitleString, 12)
'Assign new title to series.
TChart1.Series(i).Title = TitleString
Next i
End Sub
Revising your requirements, I suggest you an other alternative that reduces the Legend Text, but the title of series remains intact. Could you please check if next code works as you want?
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scLine
TChart1.AddSeries scLine
Dim i As Integer
TChart1.Series(0).AddXY 0, 30, "", clTeeColor
TChart1.Series(0).AddXY 10, 100, "", clTeeColor
TChart1.Series(1).AddXY 0, 50, "", clTeeColor
TChart1.Series(1).AddXY 50, 120, "", clTeeColor
TChart1.Series(0).Title = "DDDDAAAAFFFFLLLLRRRRSSSS"
TChart1.Series(1).Title = "AAAALLLLSSSSTTTTEEEERRRR"
' TChart1.Legend.ShapeBounds.Right = 100
TChart1.Legend.Left = 100
TChart1.Legend.CustomPosition = True
TChart1.Legend.Width = 100
End Sub
Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
If ValueIndex <> -1 Then
'Calculate the size of string
Dim LenString As Integer
LenString = Len(TChart1.Series(ValueIndex).Title)
'First replace the Left chars for ...
Dim TitleString As String
TitleString = TChart1.Series(ValueIndex).Title
Mid$(TitleString, 10, 3) = "..."
'After cut the string
TitleString = Left(TitleString, 12)
'Assign new text to LegendText
LegendText = TitleString
End If
End Sub
I hope will helps.
Thanks.
Related
i have this table
animals = {
{sname = "bunny", name = "bunny hase", size = 4, size2 = 8, size3 = 9},
{sname = "mouse", name = "Micky Mouse", size = 1, size2 = 12, size3 = 22},
{sname = "cow", name = "Die Kuh", size = 30, size2 = 33, size3 = 324
}
there i can search by a listed entry
for _,v in pairs(animals) do
if v.sname == "bunny" then
print(v.sname, v.name, v.size, v.size2, v.size3)
break
end
end
and get the result:
bunny bunny hase 4 8 9
Now i want to search in my table by starting with a single Letter, for example "b", that show me all the entries starting with the letter "b" to get the same result?
I found no Solution. May you can help me?
First: The table animals needs a trailing } ;-)
Put it in a Lua -i console and play around with...
>animals = {
{sname = "bunny", name = "bunny hase", size = 4, size2 = 8, size3 = 9},
{sname = "mouse", name = "Micky Mouse", size = 1, size2 = 12, size3 = 22},
{sname = "cow", name = "Die Kuh", size = 30, size2 = 33, size3 = 324}
}
-- Now set a __call metamethod on same table
>setmetatable(animals,{__call=function(tab,...)
local args={...}
for key, value in pairs(tab) do
if value.sname:find(args[1],1) then print(key,'=',value.sname) end
end
end})
table: 0x565c4a00
-- Lets try it once
>animals('b')
1 = bunny
-- Next one
>animals('c')
3 = cow
-- Last one
>animals('m')
2 = mouse
Using metatables holds your stuff together.
Another fine place is the __index metamethod that can hold all functions you need for that table and can be used like the string functions on a string.
( Like: value.sname:find(args[1],1) )
This leads to the heart of what find should do.
In first example it looks in whole sname for a matching pattern.
Check the Lua patterns what also can be useful.
Maybe a ^ only for the begining sounds smart?
So construct the find pattern: '^'..args[1]
...and use more than one letter if you have a cow, crow, frog and fish in your animals.
Example with function name find in __index
>animals = {
{sname = "bunny", name = "bunny hase", size = 4, size2 = 8, size3 = 9},
{sname = "mouse", name = "Micky Mouse", size = 1, size2 = 12, size3 = 22},
{sname = "cow", name = "Die Kuh", size = 30, size2 = 33, size3 = 324}
}
-- Place a find function into __index
>setmetatable(animals,{__index={find=function(tab,...)
local args={...}
for key, value in pairs(tab) do
if value.sname:find('^'..args[1]) then print(key,'=',value.sname) end
end
end}})
table: 0x565c3db0
-- first
>animals:find('c')
3 = cow
-- next
>animals:find('m')
2 = mouse
-- last
>animals:find('b')
1 = bunny
If you like to print all key values then extend the print() in find().
Stop, i found an issue....
Look here - i prefer the first solution:
animals = {
{sname = "bunny", name = "bunny hase", size = 4, size2 = 8, size3 = 9},
{sname = "mouse", name = "Micky Mouse", size = 1, size2 = 12, size3 = 22},
{sname = "cow", name = "Die Kuh", size = 30, size2 = 33, size3 = 324}
}
-- Now set a __call metamethod on same table
setmetatable(animals,{__call=function(tab,...)
local args={...}
for v,k in pairs(tab) do
if k.sname:find(args[1],1) then print(v,'=',k.sname) end
end
end})
-- Search Entries with Start U.....
-- there should be no result, but....
animals('u')
i get the Result:
1 = bunny
2 = mouse
that should not be the result!
I am new to Kivy and this is my first time trying to create a scrollView.
I am trying to do a 'Splitwise' ripoff where you can create expenses and let the app figure out who should pay who etc.
I am trying to create a method that opens a popup with all members and their balances as well as a button with the text 'Settle up'. Underneath the balances should be a list of all the registered debts, and you should be able to scroll down to see them all. The popup should also contain a 'Cancel'-button.
My problem is that my code doesn't enable scrolling, and also squishes together the content in the pop up. See picture.
All help highly appreciated!
See (messy) code below:
sbl_ret = GridLayout(cols = 1)
sbl_balances = GridLayout(cols = 3)
sbl_balances.add_widget(Label())
sbl_balances.add_widget(Label(text = 'Balances', font_size = '20sp', size_hint = (1,.2), color = backgroundColor, bold = True))
sbl_balances.add_widget(Label())
for member in self.members:
sbl_balances.add_widget(Label(text = member.getName(), font_size = 40, size_hint_y = None, height = 60))
sbl_balances.add_widget(Label(text = str(round(member.getBalance())) + ' kr', font_size = 40, size_hint_y = None, height = 60))
sbl2 = BoxLayout(orientation = 'vertical')
sbl2.add_widget(Label(size_hint = (1,.2)))
btn = Button(text = 'Settle up', background_color = buttonColor, bold = True, size_hint_y = None, height = 60)
btn.bind(on_press = lambda member: self.settleUp())
sbl2.add_widget(btn)
sbl2.add_widget(Label(size_hint = (1,.2)))
sbl_balances.add_widget(sbl2)
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(text = 'Debts', font_size = '20sp', color = backgroundColor, bold = True))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
for member in self.members:
for debt in member.getDebtList():
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(size_hint_y = None, height = 60, text = debt.getToWhom().getName() + ' lent ' + str(debt.getAmount()) + ' SEK to ' + debt.getFromWhom().getName() + ' for ' + debt.getDescription(), font_size = 40))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.bind(minimum_height=sbl_balances.setter('height'))
sbl3 = BoxLayout(size_hint = (1,.15))
sbl3.add_widget(Label(size_hint = (.2,1)))
b = Button(text = 'Cancel', background_color = entryColor, size_hint_y = None, height = 150)
b.bind(on_press = lambda x: self.balanceDialog.dismiss())
sbl3.add_widget(b)
sbl3.add_widget(Label(size_hint = (.2,1)))
sv = ScrollView(do_scroll_x = False)
sv.add_widget(sbl_balances)
sbl_ret.add_widget(sv)
sbl_ret.add_widget(sbl3)
self.balanceDialog = Popup(title = 'Group view', content = sbl_ret, title_align = 'center',
title_color = backgroundColor, background_color = [0,0,0,.7], separator_height = 0, title_size = '28sp')
self.balanceDialog.open()
'''
Try adding size_hint_y=None to your code creating the GridLayout:
sbl_balances = GridLayout(cols = 3, size_hint_y=None)
See the documentation.
I have this problem and all possible solutions I'm looking for online hasn't helped me. Is there a way to make a table like in a string format?
What I'm expecting the output will be like this for a string:
Category
ITEM1 QTY PRICE TOTAL
ITEM2 QTY PRICE TOTAL
but my output code is like this:
Category
ITEM1 QTY PRICE TOTAL
ITEM2 QTY PRICE TOTAL
Category
ITEM1 QTY PRICE TOTAL
ITEM2 QTY PRICE TOTAL
I figured out something that the item string length is the cost why they are not aligned formally in my format, but is there a way on how to solve this issue? I'm totally new in swift.
here is my code:
for category in self.categoryList {
sentence += "Category: \(category)\n"
for items in self.productList {
if category == items.category {
grandTotal += Double(items.qty)! * Double(items.price)!
let total: Double = Double(items.qty)! * Double(items.price)!
let item = (items.item as NSString).utf8String
let qty = (items.qty as NSString).utf8String
let price = (items.price as NSString).utf8String
sentence += String(format: "%-10s%20s%15s%15.02f\n", item!, qty!, price!, total)
}
}
sentence += "\n\n"
grandTotal = 0
}
lblData.text = sentence
You could pad your strings to a defined length:
let elements = ["ITEM1", "QTY", "PRICE", "TOTAL"]
// without padding
var sentence = ""
for e in elements {
if !sentence.isEmpty {
sentence += " "
}
sentence += e
}
print(sentence)
// prints "ITEM1 QTY PRICE TOTAL"
// with padding
sentence = ""
for e in elements {
sentence += e.padding(toLength: 10, withPad: " ", startingAt: 0)
}
print(sentence)
// prints "ITEM1 QTY PRICE TOTAL "
Or in a shorter form:
// without padding
var sentence = elements.joined(separator: " ")
print(sentence)
// with padding
sentence = elements.map({$0.padding(toLength: 10, withPad: " ", startingAt: 0)}).joined(separator: " ")
print(sentence)
I want to export data from a listbox,
Listbox1.AddRow "001", "Orange", "1.00","Arief"
Listbox1.AddRow "001", "Apple", "1.00","Arief"
Listbox1.AddRow "001", "Banana", "1.00","Arief"
Listbox1.AddRow "004", "Orange", "1.00","Arief"
Listbox1.AddRow "005", "Apple", "1.00","Brandon"
Listbox1.AddRow "006", "Banana", "1.00","Brenda"
dim f as folderitem
dim tisx as TextOutputStream
f = new folderitem("item.txt")
tisx = f.CreateTextFile
dim Last_first_word as String
dim maxRow as Integer = Listbox1.listcount-1
for row as integer = 0 to maxRow
if Listbox1.Cell(row,0)<> Last_first_word then
tisx.WriteLine ""
tisx.writeline listBox1.cell(row,0)
tisx.WriteLine listBox1.cell(row,1)+" "+listBox1.cell(row,2)
Last_first_word=Listbox1.Cell(row,0)
else
tisx.WriteLine listBox1.cell(row,1)+" "+listBox1.cell(row,2)
end if
next
tisx.Close
I want to categorized all the items which is has the same code,and put the name at the last.
How to make the result like ,
001
Orange 1.00
Apple 1.00
Banana 1.00
Arief
004
Orange 1.00
Arief
005
Apple 1.00
Brandon
006
Banana 1.00
Brenda
Thanks
Regards,
Arief
You'll need to also save the name so you can display it before you move onto a new group of data. Only a minor tweak to your code was needed:
Listbox1.DeleteAllRows
ListBox1.AddRow("001", "Orange", "1.00", "Arief")
ListBox1.AddRow("001", "Apple", "1.00", "Arief")
ListBox1.AddRow("001", "Banana", "1.00", "Arief")
ListBox1.AddRow("004", "Orange", "1.00", "Arief")
ListBox1.AddRow("005", "Apple", "1.00", "Brandon")
ListBox1.AddRow("006", "Banana", "1.00", "Brenda")
Dim f As FolderItem
Dim tisx As TextOutputStream
f = SpecialFolder.Desktop.Child("item.txt")
tisx = f.CreateTextFile
Dim Last_first_word As String
Dim lastName As String
Dim maxRow As Integer = Listbox1.ListCount - 1
For row As Integer = 0 To maxRow
If Listbox1.Cell(row, 0) <> Last_first_word Then
If lastName <> "" Then tisx.WriteLine(lastName)
tisx.WriteLine("")
tisx.WriteLine(ListBox1.Cell(row, 0))
tisx.WriteLine(ListBox1.Cell(row, 1) + " " + ListBox1.Cell(row, 2))
Last_first_word = ListBox1.Cell(row, 0)
lastName = ListBox1.Cell(row, 3)
Else
tisx.WriteLine(ListBox1.Cell(row, 1) + " " + ListBox1.Cell(row, 2))
End If
Next
If lastName <> "" Then tisx.WriteLine(lastName)
tisx.Close
The data has to be sorted by that group number in order for this to work.
Thank you for all the support with lua, I'm very new and my application is working nicely so far.
I've made an app that will take in a few thousand numbers for different items. I'm trying to find the Mean/Media/Mode for each item, I've been able to do this for a single item, but not for all items.
Here is my table structure:
for i = 0, 1500 do
local e = {}
e.seller,
e.buyer,
e.itemName,
e.soldAmount = GetSoldAmount(FromMember(i))
table.insert(allSalesTempTable, e)
end
Table output format
[1] =
{
["itemName"] = [[Salad]]
["buyer"] = [[#Mike]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
},
[2] =
{
["itemName"] = [Pizza]
["buyer"] = [[#James]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
},
[3] =
{
["itemName"] = [Salad]
["buyer"] = [[#Frank]],
["eventType"] = 15,
["soldAmount"] = 75,
["seller"] = [[#Sarah]],
},
[4] ...
},
Then I'm trying to send the table/array to this mean function
stats={}
-- Get the mean value of a table
function stats.mean( t )
local sum = 0
local count= 0
local tempTbl = {}
(This is completely not going to work, but its what I'm trying so far)
for k,v in pairs(t) do tempTbl[k] = v
if v.itemName == tempTbl.itemName then
sum = sum + v.soldAmount
count = count + 1
end
end
return (sum / count)
end
--- To get the function started
stats.mean(e)
Here is where I'm getting fuzzy, Not sure if I can add the MEAN while collecting the data into the first temp table, or if it needs to be re-calculated after I have all the data?
If it needs to be done after, then my stats.mean(e) needs a way to insert it?
I'm trying to get this output:
[1] =
{
["itemName"] = [[Salad]]
["buyer"] = [[#Mike]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
["mean"] = 112.5 - New Insert somehow
},
[2] =
{
["itemName"] = [Pizza]
["buyer"] = [[#James]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
["mean"] = 150 - New Insert somehow
},
[3] =
{
["itemName"] = [Salad]
["buyer"] = [[#Frank]],
["eventType"] = 15,
["soldAmount"] = 75,
["seller"] = [[#Sarah]],
["mean"] = 112.5 - New Insert somehow
},
[4] ...
},
I've been working on this problem for a few days, After I see how to adjust my format for the mean and insert into the existing table I'll be able to figure out mean/min/max/median/mode easy enough.