Greetings,
When using the Click_Series Event how can you determine what the index of the series is that is under the mouse.
i.e. TeeChart.Series[n] ... what is n ...
Right now I am using the series name and then iterating through the series collection until the name matches counting all the way .. and thats how I get my 'n' ...
Is there a better way ?
TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index
TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index
--------------------
Cheers Phil.
Cheers Phil.
Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index
Hello Snarkle,
If you are using TChart1.SeriesClick Event you could use its parameters: series, valueindex, and MouseEvent.
I propose simple code that I think you can use in your project.
Could you please, check if previous code works as you want?
I hope will helps.
Thanks,
If you are using TChart1.SeriesClick Event you could use its parameters: series, valueindex, and MouseEvent.
I propose simple code that I think you can use in your project.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
tChart1.ClickSeries += new Steema.TeeChart.TChart.SeriesEventHandler(tChart1_ClickSeries);
}
void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
{
this.Text = s[valueIndex].X.ToString();
}
I hope 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 |
Instructions - How to post in this forum |
Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index
Thanks for the reply Sandra ...
My Bad I wasn't very clear in my email .. this is what I am currently doing to find the index of a series.
The idea is that after clicking on a series (apart from the coloring stuff) in the variable 'SeriesIndex' I have the index of the Series under the mouse, so in another part of the code I can use a call such as StockChart.Series[SeriesIndex].Title = "Selected Series" (amongst other calls I wish to make);
The above code will do that as long as I dont get double ups in the series title (which sadly can happen) and looping through the series on every click will probably turn out to be most inefficient once I start having many more series in the chart.
Cheers Phil.
My Bad I wasn't very clear in my email .. this is what I am currently doing to find the index of a series.
Code: Select all
private void StockChart_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
{
Series tmpSeries = (Series)s;
SelectedSeriesX = tmpSeries.Title;
/// todo - Temp until I find a better method to find Series index.
int count = 0;
foreach (Series ss in StockChart.Series)
{
if (ss.Title == SelectedSeriesX)
SeriesIndex = count;
ss.Color = Color.Black;
count++;
}
tmpSeries.Color = Color.Red;
}
The idea is that after clicking on a series (apart from the coloring stuff) in the variable 'SeriesIndex' I have the index of the Series under the mouse, so in another part of the code I can use a call such as StockChart.Series[SeriesIndex].Title = "Selected Series" (amongst other calls I wish to make);
The above code will do that as long as I dont get double ups in the series title (which sadly can happen) and looping through the series on every click will probably turn out to be most inefficient once I start having many more series in the chart.
Cheers Phil.
--------------------
Cheers Phil.
Cheers Phil.
Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index
Hello Phil,
Ok. I have made a simple code that I think that you can help you. Please, see next code and check if it works as you want:
I hope will helps.
Thanks,
Ok. I have made a simple code that I think that you can help you. Please, see next code and check if it works as you want:
Code: Select all
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
for (int i = 0; i < 5; i++)
{
(tChart1.Series.Add(new Steema.TeeChart.Styles.Line())).FillSampleValues();
}
tChart1.ClickSeries += new Steema.TeeChart.TChart.SeriesEventHandler(tChart1_ClickSeries);
}
private int SeriesIndex;
void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
{
SeriesIndex = tChart1.Series.IndexOf(s);
for (int i = 0; i < tChart1.Series.Count; i++)
{
tChart1[i].Color = (i == SeriesIndex) ? Color.Red : Color.Black;
}
}
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index
AHA ...
SeriesIndex = tChart1.Series.IndexOf(s);
Thats the ticket !!!... thanks ...
SeriesIndex = tChart1.Series.IndexOf(s);
Thats the ticket !!!... thanks ...
--------------------
Cheers Phil.
Cheers Phil.