Selection of bar from bar chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Chris.CHWU
Newbie
Newbie
Posts: 57
Joined: Wed Jan 30, 2008 12:00 am

Selection of bar from bar chart

Post by Chris.CHWU » Thu Jul 30, 2009 7:12 am

Greetings,

I'm trying to figure out how to provide the following feature to my users.
I have a bar chart which have some series, and I want to highlight selected bar after selection(by mouse click).
But the problem is that for some series (bar), I don't know how to selected correct ?

How can I achieve this? What's chart event i can use?
Do you have any suggestion?

Thanks in advance.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Selection of bar from bar chart

Post by Sandra » Thu Jul 30, 2009 10:31 am

Hello chris,

I made a simple project that I think help to solve your problem, doing a similar code as next. Please check next code works fine in your application.

Code: Select all

  public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.Bar bar1;
        private void InitializeChart()
        {
            bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.FillSampleValues(5);
            tChart1.ClickSeries += new Steema.TeeChart.TChart.SeriesEventHandler(tChart1_ClickSeries);
        }

        int series = -1;
        int index = -1;

        void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
        {
            if ((series != -1) && (index != -1))
            {
                tChart1[series].Colors[index] = tChart1[series].Color;
            }

            Text = s.ValueMarkText(valueIndex);
            s.Colors[valueIndex] = Color.Lime;
            index = valueIndex;
            series = tChart1.Series.IndexOf(s);
            tChart1.Refresh();
        }
I hope that will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selection of bar from bar chart

Post by Yeray » Thu Jul 30, 2009 11:01 am

Hi Chris,

As an update, you could note some problems with the colors in Sandra's example. Forcing the series to work with coloreach, you shouldn't find problems:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        Steema.TeeChart.Styles.Bar bar1, bar2, bar3;

        private void InitializeChart()
        {
            bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar2 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar3 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);

            bar1.ColorEach = true;
            bar2.ColorEach = true;
            bar3.ColorEach = true;

            Random rnd = new Random();
            for (int i = 0; i < 5; i++)
            {
                bar1.Add(i, rnd.Next(1000), "", bar1.Color);
                bar2.Add(i, rnd.Next(1000), "", bar2.Color);
                bar3.Add(i, rnd.Next(1000), "", bar3.Color);
            }

            tChart1.ClickSeries += new Steema.TeeChart.TChart.SeriesEventHandler(tChart1_ClickSeries);
            
        }

        int series = -1;
        int index = -1;

        void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
        {
            if ((series != -1) && (index != -1))
            {
                tChart1[series].Colors[index] = tChart1[series].Color;
            }

            Text = s.ValueMarkText(valueIndex);
            s.Colors[valueIndex] = Color.Lime;
            index = valueIndex;
            series = tChart1.Series.IndexOf(s);
            tChart1.Refresh();
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Chris.CHWU
Newbie
Newbie
Posts: 57
Joined: Wed Jan 30, 2008 12:00 am

Re: Selection of bar from bar chart

Post by Chris.CHWU » Mon Aug 03, 2009 11:44 am

Thanks your advise!!
But i have a problem about event~
I am trying mouse up and mouse down event to handle the bar chart selection, but i can'tchange the bar color (only bar styles). How can i modify it that changebar color ?!

Code: Select all

Dim bar As Steema.TeeChart.Styles.Bar = Nothing 
If TypeOf series Is Steema.TeeChart.Styles.Bar Then
bar = CType(series, Steema.TeeChart.Styles.Bar)
AddHandler bar.GetBarStyle, AddressOfp_getbarstyle

Code: Select all

Private Sub p_getbarstyle( _
            ByVal bar As Steema.TeeChart.Styles.CustomBar, _
             ByVal e As Steema.TeeChart.Styles.Bar.GetBarStyleEventArgs)

     If e.ValueIndex = -1 Then
     Return
     End If

     If _dicTrendTitle2Selected.ContainsKey(bar.Title) = True Then
        If Me._dicTrendTitle2Selected(bar.Title)(e.ValueIndex) = True   Then
             e.Style = Styles.BarStyles.Ellipse
         End If 
      End If
End Sub

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selection of bar from bar chart

Post by Yeray » Mon Aug 03, 2009 2:11 pm

Hi Chris,

Here is the example in VB that seems to work fine here:

Code: Select all

Public Class Form1
    Dim bar1 As Steema.TeeChart.Styles.Bar

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        bar1 = New Steema.TeeChart.Styles.Bar
        TChart1.Series.Add(bar1)

        Dim Rnd As Random = New Random()

        For i As Integer = 1 To 10
            bar1.Add(i, Rnd.Next(1000), "", bar1.Color)
        Next

        bar1.ColorEach = True

        AddHandler TChart1.ClickSeries, AddressOf p_ClickSeries
    End Sub

    Dim series As Integer = -1
    Dim index As Integer = -1

    Private Sub p_ClickSeries( _
            ByVal sender As Object, _
            ByVal s As Steema.TeeChart.Styles.Series, _
            ByVal Valueindex As Integer, _
            ByVal e As System.Windows.Forms.MouseEventArgs)

        If ((series <> -1) And (index <> -1)) Then
            TChart1(series).Colors(index) = TChart1(series).Color
        End If

        Text = s.ValueMarkText(Valueindex)
        s.Colors(Valueindex) = Color.Lime
        index = Valueindex
        series = TChart1.Series.IndexOf(s)
        TChart1.Refresh()
    End Sub
End Class
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Chris.CHWU
Newbie
Newbie
Posts: 57
Joined: Wed Jan 30, 2008 12:00 am

Re: Selection of bar from bar chart

Post by Chris.CHWU » Tue Aug 04, 2009 1:41 am

I try the example is ok, thanks!
I still have some problems.

1. How to cancel the series click color? if i don't want highlight the bar.

2. I want to select certain bar by draging a rectangle region, and highlight the bar. (after selection).Then i could set the bar color.

I tried MouseDown and MouseUp to selection the bar and redraw the chart, the event of "Steema.TeeChart.Styles.GetPointerStyleEventArgs" i just get the style attribute.
How can i change the bar color?
未命名-2.png
未命名-2.png (64.26 KiB) Viewed 12753 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selection of bar from bar chart

Post by Yeray » Tue Aug 04, 2009 2:06 pm

Hi Chris,

I'm not sure to understand why don't you use the same OnClickSeries event like in the example from above.
Could you please attach here a simple example project we can run as-is to reproduce the problem here? If we can see it, it would help us to understand what are you exactly trying to achieve and try to suggest you a solution.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply