TeeChart On Mouse Over a series display a user define Image - activex

My requirement is I want to display a Image box when a user perform a mouse over on a bar in the chart. Currently in mouse over we are displaying the text such as label, Percentage etc can we display Image as well.
Thanks
Akshay

You can use a hidden Rectangle tool to show the desired image and use the provided events to change its visibility, position, or the image loaded.
Ie, using OnMouseEnterSeries/OnMouseLeaveSeries, but the same could be done with OnMouseMove event:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues
TChart1.Tools.Add tcMarksTip
TChart1.Tools.Add tcRectangle
TChart1.Tools.Items(1).Active = False
TChart1.Tools.Items(1).asRectangle.AllowDrag = False
TChart1.Tools.Items(1).asRectangle.AllowResize = False
TChart1.Tools.Items(1).asRectangle.Shape.Transparency = 0
End Sub
Private Sub TChart1_OnMouseEnterSeries(ByVal SeriesIndex As Long)
ValueIndex = TChart1.Series(SeriesIndex).Clicked(TChart1.MousePosition.X, TChart1.MousePosition.Y)
If ValueIndex = 2 Then
TChart1.Tools.Items(1).Active = True
TChart1.Tools.Items(1).asRectangle.Shape.Picture.LoadImage "C:\tmp\ImageForValueIndex2.png"
TChart1.Tools.Items(1).asRectangle.Left = TChart1.MousePosition.X
TChart1.Tools.Items(1).asRectangle.Top = TChart1.MousePosition.Y
End If
End Sub
Private Sub TChart1_OnMouseLeaveSeries(ByVal SeriesIndex As Long)
TChart1.Tools.Items(1).Active = False
End Sub
Edit:
As noticed in the comment below, TeeChart VCL v2014.11 introduced SystemHints property as explained here:
MarksTip tool new property SystemHints (boolean default True in VCL,
False in Firemonkey). When False, a normal TeeShape object is used to
paint the tiptool instead of using the VCL system mechanism.
ChartTool3.SystemHints := False;
ChartTool3.Format.Font.Size:=14;
The only disadvantadge compared to system hints is the shape cannot be
displayed outside the chart bounds.
When SystemHints is False, the new Format property (of type TTeeShape)
contains all the formatting properties (Brush, Pen, Font, etc) to
display the hint.
Since TeeChart ActiveX is a wrapper from TeeChart VCL, you can use this new feature from TeeChart ActiveX v2014.0.0.1.
So you just have to keep in mind to set SystemHints to False if you want to use the TeeShape properties. Here it is a simple example:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues
TChart1.Tools.Add tcMarksTip
TChart1.Tools.Items(0).asMarksTip.Format.Picture.LoadImage "C:\tmp\ImageForAllValues.jpg"
TChart1.Tools.Items(0).asMarksTip.SystemHints = False
End Sub

Related

resize listbox in PySimpleGui based on length of list

I'm trying to update the Listbox in PySimpleGUI to resize based on length of list but the update(size=len(mylist) says that size is not an allowed argument. Any work around to this?
I've seen some people try to make the window/layout into a function but I'm not sure if that's the right approach.
Thanks in advance.
Basically, the height or the width of a Listbox element should not be revised after initialized, or the size of window will be also changed and maybe out of screen.
There's no option provided to change the height or the width of the Listbox element in PySimpleGUI, but you can do it by tkinter code, element.Widget.configure(height=height, width=width).
Example Code
import PySimpleGUI as sg
name_list = sorted(['James', 'Robert', 'John', 'Michael', 'David', 'William', 'Richard', 'Joseph', 'Thomas', 'Charles'])
layout = [
[sg.Input('', key='Name'), sg.Button('Add')],
[sg.Listbox(name_list, size=(20, len(name_list)), expand_x=True, key='Names')],
]
window = sg.Window('Title', layout, finalize=True)
window['Name'].bind('<Return>', ' Return')
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
elif event in ('Add', 'Name Return'):
name = values['Name']
if name and name not in name_list:
name_list = sorted(name_list+[name])
window['Names'].Widget.configure(height=len(name_list))
window['Names'].update(values=name_list)
window.move_to_center()
window.close()

UISegmentedControl with rounded corner and non proportional segments bug

i recently updated a rounded corner segment control to have different width for each segment.
the issue i have is that the last segment doesn't align properly with the end of the segmented control
i just used this code for this sample (seg being my segmented control) :
seg.layer.borderWidth = 1
seg.layer.cornerRadius = seg.bounds.height / 2
seg.layer.masksToBounds = true
seg.apportionsSegmentWidthsByContent = true
if i remove the masksToBounds line i can see that the right segment doesn't reach the edge of the segmented control.
is there any way to fix this issue?
It appears that this is caused by a rendering bug in UISegmentedControl when apportionsSegmentWidthsByContent = true. I couldn't find a simple workaround by manipulating the CALayers of the control. You can create a custom control using UIStackView to mimic the UISegmentedControl.
You should also file a radar with Apple.
I don't know if this still affects iOS, but a workaround in Xamarin.iOS is: Override UISegmentView, calculate text width of the last segment element and update it's width.
Sample code in C#:
public class MySegmentedControl : UISegmentedControl
{
public override void MovedToSuperview ()
{
// Fix truncation of last element
// when ApportionsSegmentWidthsByContent = true
if (ApportionsSegmentWidthsByContent) {
RecalculateLastSegmentWidth ();
}
}
private void RecalculateLastSegmentWidth()
{
var font = UIFont.FromName("Helvetica", 12);
var lastSegment = NumberOfSegments - 1;
var segmentTitle = TitleAt(lastSegment);
var segmentWidth = segmentTitle.StringSize(font).Width + 20;
SetWidth(segmentWidth, lastSegment);
}
}

Vertical Scroll bar for Top and Bottom Legends

I want to align my legend to the Bottom of my chart because the no of Character present in my legend are around 100.
Please let me know how I can provide a vertical toolbar to that so that legend box size remains constant also whether there is a way we can round off the Text in label.
Thanks
Akshay
The tcLegendScrollBar tool is designed to show the items in the legend that don't fit in the legend rectangle, not to limit the number of characters shown in the items. Here it is an example usign it:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
Dim i As Integer
For i = 0 To 10
TChart1.AddSeries scFastLine
TChart1.Series(i).FillSampleValues 10
TChart1.Series(i).Title = "this is a very very veeeeeeery long string to be shown in the legend as title for the series " + Str$(i)
Next i
TChart1.Legend.MaxNumRows = 5
TChart1.Tools.Add tcLegendScrollBar
End Sub
To limit the length of the strings in the legend you can use the OnGetLegendText event. Ie:
Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
LegendText = Left$(LegendText, 10) + "..."
End Sub

TEdit and focus selection works different depending on Show/showmodal

When switching focus between TEdits, the selection changes depending on the way you show the form.
When you show it with Form.show, and swith between two TEdits, the text is selected.
When you show the form with Form.Showmodal, And switch between, the cursor is at the end of the newly focused TEdit
reproduce :
Create a new form with 2 TEdits, type some text in both. Then switch between both TEdits, the whole text is selected, but when I show the form with Modal, The caret is positioned behind the text.
Why is there a difference in functionality? And where can I change it.
I found the code responsible :
procedure TStyledEdit.DoEnter;
var
Form: TCommonCustomForm;
begin
inherited;
Form := TCommonCustomForm(Root);
if not Model.IsReadOnly and Model.InputSupport and not FTextService.HasMarkedText and
((Form = nil)
//next part returns false
or (Form.FormState * [TFmxFormState.Showing] = [TFmxFormState.Showing]) or
(Form.FormState = [TFmxFormState.Engaged])) then
Edit.SelectAll
else
begin
UpdateSelectionPointPositions;
UpdateCaretPosition;
end;
end;
DoEnter is a protected method and as such you can override with your own method if you wish.
You can either do this the classic way by creating your own descendant class (with a different type name) or you can use the so-called interceptor classes as described in this link: interceptor classes.
I believed that you need to extend the if clause like this (but not tested - sorry)
if not Model.IsReadOnly and Model.InputSupport and not FTextService.HasMarkedText and
((Form = nil)
or (Form.FormState * [TFmxFormState.Showing] = [TFmxFormState.Showing])
or (Form.FormState * [TFmxFormState.Modal] = [TFmxFormState.Modal])
or (Form.FormState = [TFmxFormState.Engaged])) then

Line Chart Pointer color Change

I am using the pointer '+' in my code. In the legend it is displayed in black color.I want that to be displayed as legend color.
If I change the property from editting=>series=>pointer=>default- TRUE it works fine for me.
Can you let me know how this can be achieved through code.
Thanks
Akshay
I'm not 100% sure about your which is your exact question. If I understood correctly you should change pointer's pen color:
TChart1.Series(0).asLine.Pointer.Pen.Color = TChart1.Series(0).Color
A complete VB6 example:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scLine
TChart1.Series(0).FillSampleValues 10
TChart1.Series(0).asLine.Pointer.Visible = True
TChart1.Series(0).asLine.Pointer.Style = psCross
TChart1.Series(0).asLine.Pointer.Pen.Color = TChart1.Series(0).Color
End Sub
If this doesn't help please provide more detailed information about your requirements.

Resources