Page 1 of 1
Avoid points sorting in a series
Posted: Tue Nov 02, 2010 11:05 am
by 9644027
Are there any ways to avoid points being automatically sorted?
As you can see in the attached file, the values on axis are double and they are
sorted in ascendanting order. However it's not´really what I need, as the values have
to be displayed in their original order. I have already tried to use
points.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None before populating the series, but it doesn't work.
In my example the first bar should be the one with x value 1246 (mot 1204), second with 1247,...
I hope you have some suggestions.
Regards
Re: Avoid points sorting in a series
Posted: Tue Nov 02, 2010 2:00 pm
by narcis
Hi Brinet,
Code snippet below works fine for me here using latest TeeChart for .NET 2010 avaiable at the client area. Does it work fine at your end? Does this solve the problem at your end? If it doesn't please modify the code snippet below or attach a simple example project we can run "as-is" to reproduce the problem here and let us know the TeeChart version you are using.
Code: Select all
Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
Random x = new Random();
Random y = new Random();
for (int i = 0; i < 10; i++)
{
bar1.Add(x.Next(), y.Next(), i.ToString());
}
tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Value;
Thanks in advance.
Re: Avoid points sorting in a series
Posted: Tue Nov 02, 2010 4:17 pm
by 9644027
Unfortunately your solution doesn't work for me. The x axis values are sorted in ascendanting order, again. And for our purposes they shouldn't
be sorted. I have a following piece of code:
Code: Select all
private void SearchForSecondSelectionData(string tablename, string startDateTime, string endDateTime, string index)
{
WebServerClient.WebServerService.CWSRPCommClient proxy = new WebServerClient.WebServerService.CWSRPCommClient();
response = Conversions.ObserveAreaToStringStringArray(proxy.SearchForTableData(tablename, startDateTime, endDateTime, index));
if (tChart1 == null)
tChart1 = FindName("tChart") as Steema.TeeChart.TChart;
tChart1.Series.Clear();
if (points == null)
points = new Steema.TeeChart.Styles.Bar();
else
points.Clear();
tChart1.Series.Add(points);
points.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
// tChart1.Series.Add(points);
for (int i = 0; i < response.Length; i++)
{
String date = response[i][0].Substring(0, 19);
String slagmass = response[i][1];
double dslagmass = Convert.ToDouble(slagmass);
if (cbChartType.SelectedIndex == 5)
dslagmass *= 1000;
points.Add(Convert.ToDouble(response[i][2].ToString()),dslagmass);
}
tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
}
The values from the database are inserted in the array
response. These values musn't be sorted!
However they are.
((( Can you plase tell me help me how can I solve this problem, that has already taken me two days.
I use TeeChart .Net v2.
Thank you!
Re: Avoid points sorting in a series
Posted: Wed Nov 03, 2010 8:27 am
by narcis
Hi Brinet,
The code snippet I posted also works fine using latest v2 release available. Can you please arrange a simple example project we can run "as-is" to reproduce your problem here? You could populate the array manually.
Thanks in advance.
Re: Avoid points sorting in a series
Posted: Wed Nov 03, 2010 9:38 am
by 9644027
Thank you very much for your response.
Here is the code with manually populated string string array.
I hope you will be able to reproduce the problem. It still doesn't work.
Code: Select all
private void Func()
{
InitializeArray();
if (tChart1 == null)
tChart1 = FindName("tChart") as Steema.TeeChart.TChart;
tChart1.Series.Clear();
if (points == null)
points = new Steema.TeeChart.Styles.Bar();
else
points.Clear();
tChart1.Series.Add(points);
points.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
for (int i = 0; i < response.Length; i++)
{
String slagmass = response[i][1];
double dslagmass = Convert.ToDouble(slagmass);
points.Add(Convert.ToDouble(response[i][0].ToString()), dslagmass);
}
}
private void InitializeArray()
{
response = new String[13][];
for (int i = 0; i < response.Length; i++)
{
response[i] = new String[] { "", "" };
}
response[0][0] = "0001633";
response[1][0] = "0001634";
response[2][0] = "0001635";
response[3][0] = "0001636";
response[4][0] = "0001621";
response[5][0] = "0001640";
response[6][0] = "0001622";
response[7][0] = "0001641";
response[8][0] = "0001623";
response[9][0] = "0001647";
response[10][0] = "0001637";
response[11][0] = "0001648";
response[12][0] = "0001642";
response[0][1] = "103.621";
response[1][1] = "113.109";
response[2][1] = "139.209";
response[3][1] = "115.021";
response[4][1] = "986.835";
response[5][1] = "165.181";
response[6][1] = "152.182";
response[7][1] = "117.816";
response[8][1] = "113.72";
response[9][1] = "124.243";
response[10][1] = "115.363";
response[11][1] = "130.747";
response[12][1] = "150.621";
}
Thank you!!!
Re: Avoid points sorting in a series
Posted: Wed Nov 03, 2010 9:56 am
by narcis
Hi Brinet,
For simplicity I used your code in a WinForms application, dropping a TChart component into a WinForm and using code snippet below. It's almost idential to yours with very little changes.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Dock = DockStyle.Fill;
InitializeArray();
Steema.TeeChart.Styles.Bar points = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
points.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
for (int i = 0; i < response.Length; i++)
{
String slagmass = response[i][1];
double dslagmass = Convert.ToDouble(slagmass);
points.Add(Convert.ToDouble(response[i][0].ToString()), dslagmass, i.ToString());
}
}
private String[][] response;
private void InitializeArray()
{
response = new String[13][];
for (int i = 0; i < response.Length; i++)
{
response[i] = new String[] { "", "" };
}
response[0][0] = "0001633";
response[1][0] = "0001634";
response[2][0] = "0001635";
response[3][0] = "0001636";
response[4][0] = "0001621";
response[5][0] = "0001640";
response[6][0] = "0001622";
response[7][0] = "0001641";
response[8][0] = "0001623";
response[9][0] = "0001647";
response[10][0] = "0001637";
response[11][0] = "0001648";
response[12][0] = "0001642";
response[0][1] = "103.621";
response[1][1] = "113.109";
response[2][1] = "139.209";
response[3][1] = "115.021";
response[4][1] = "986.835";
response[5][1] = "165.181";
response[6][1] = "152.182";
response[7][1] = "117.816";
response[8][1] = "113.72";
response[9][1] = "124.243";
response[10][1] = "115.363";
response[11][1] = "130.747";
response[12][1] = "150.621";
}
Using code above with latest TeeChart for .NET v2 release available at the client download area I got this chart:
- NonSortedBar.jpg (137.62 KiB) Viewed 14377 times
As can be seen in bars marks, they are not sorted. Do you get the same at your end? Are you using latest v2 release available?
Thanks in advance.
Re: Avoid points sorting in a series
Posted: Wed Nov 03, 2010 10:43 am
by 9644027
Helo Narcis,
thank you for your reply. However, the values in your example are sorted though.
The first bar for example has value greater that 900 which correspondes to array element
with x value that is equal to 0001621. And this bar should be fifth bar on the graph.
I am not sure if I was clear , but I need the values to be displayed in exactly the same order as they are stored in the array.
So what I want is the following:
FIRST BAR: X VALUE = 0001633
Y VALUE = 103.621
SECOND BAR: X VALUE = 0001634
Y VALUE = 113.109
THIRD BAR: X VALUE = 0001635
Y VALUE = 139.209
FORTH BAR: X VALUE = 0001636
Y VALUE = 115.021
FIFTH BAR: X VALUE = 0001621
Y VALUE = 986.8354 AND SO ON,....
I hope I have explained better what I really need.
Thank you very much.
Re: Avoid points sorting in a series
Posted: Wed Nov 03, 2010 12:51 pm
by narcis
Hi Brinet,
Yes, I understand now what you mean but what I get I think it's correct as you are populating series using those values as X values, they are not sorted but plotted at the X position corresponding to the X value you provided. To get what you request you shouldn't use those values as X values, just use them as points labels and let series automatically use sequential X values replacing
points.Add() call in previous example for this:
Code: Select all
points.Add(dslagmass, response[i][0].ToString());
Which produces the chart below. Is that what you were looking for?
- SequentialXValues.jpg (89.17 KiB) Viewed 14354 times
BTW: If that's what you need then it's not necessary to set XValues.Order to none either.
Re: Avoid points sorting in a series
Posted: Wed Nov 03, 2010 1:54 pm
by 9644027
Thank you Narcis!
It is exactly what I need.
It works now. Thank you very much.
Regards