Page 1 of 1
How to add another series to chart.
Posted: Mon Jun 10, 2013 12:45 pm
by 13049533
Hi,
I am trying to add some more series to teechart using c#. I have the code which is working all right and now i am trying to add some more data to plot. The concept here is I have only one x-axis and multiple y-axis. First it will create a table to display data and the same data is updating in the chart. I have the code as shown below to update chart and table.
the above code is working and it creating multiple y-axis and common x-axis for all y-axis. Now i have added three more columns to table (three mores sensors data) and the data is adding to table successfully but i am not able to update in the chart. i need to create separate y-axis for these sensors also and same common x-axis for these also.i am trying to create some more y-axis for this data. I have tried in different ways but I didn't get the concept here. Because the code was written by someone else now i am trying to add some more.
I have added three more sensors data using this code.
Code: Select all
row[SystemNames.Visc] = (int)DenSensorData.visc;
row[SystemNames.Dens] = Math.Round(DensityCalib.Densityval, 2);
row[SystemNames.PermA] = PermSensorData.Pmty;
if anyone understands the above code then please help me .....
Thanks in advance.
Re: How to add another series to chart.
Posted: Tue Jun 11, 2013 12:01 pm
by 10050769
Hello veera,
Thanks for your simple code, but I can not run it here. Could you please send us a simple project or your project that we can run as-is here, because we can try to finds a solution for your problem?
Thanks,
Re: How to add another series to chart.
Posted: Wed Jun 12, 2013 11:59 am
by 13049533
Hi Sandra,
thanks for your reply,
I don't know what can i post here really because I am getting data from real sensors when you connect those sensors then only you will get data.Its a part of very big project. I have posted whatever code i have regarding chart. I have around 10 sensors in that 7 sensors are treated as analog so the above code is updation for those sensors. I have added three more sensors which are different to those already exist. Maybe i will try to update more code or as project soon that you can run.
Thanks,
Re: How to add another series to chart.
Posted: Thu Jun 13, 2013 11:16 am
by 10050769
Hello veera,
I have made a simple code, where I have added 7 series with its corresponding datatable and seems it works in correct way:
Code: Select all
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Dock = DockStyle.Fill;
this.Controls.Add(tChart1);
tChart1.Panel.MarginLeft = 20;
//GetFilter of DataSet
for (int i = 0; i < 7; i++)
{
new Line(tChart1.Chart);
tChart1[i].DataSource = GetData(i);
tChart1[i].XValues.DataMember = "X";
tChart1[i].YValues.DataMember = "Y";
tChart1[i].RefreshSeries();
CreateAxis(tChart1[i]);
}
tChart1.DoubleClick += new EventHandler(tChart1_DoubleClick);
}
private DataSet GetData(int i)
{
Random rndY= new Random();
Random rndX = new Random();
DataSet TeeDataSet = new DataSet();
DataTable TeeDataTable = new DataTable("DataTable"+i.ToString());
DataColumn xval = new DataColumn("X", typeof(double));
DataColumn yval = new DataColumn("Y", typeof(double));
TeeDataTable.Columns.Add(xval);
TeeDataTable.Columns.Add(yval);
for (int j = 0; i < 10; i++)
{
DataRow newRow = TeeDataTable.NewRow();
newRow[xval] = i+j;
newRow[yval] = rndY.Next(100);
TeeDataTable.Rows.Add(newRow);
}
TeeDataSet.Tables.Add(TeeDataTable);
return TeeDataSet;
}
private void CreateAxis(Series s)
{
Axis axis = new Axis(false, false, tChart1.Chart);
axis.Grid.Visible = true;
axis.AxisPen.Color = s.Color;
axis.Labels.Font.Color = axis.AxisPen.Color;
axis.Ticks.Color = axis.AxisPen.Color;
axis.MinorTicks.Color = axis.AxisPen.Color;
axis.Labels.Angle = 90;
axis.StartPosition = 0;
axis.EndPosition = 100;//we cannot set this to 200 as it is a % value.
tChart1.Axes.Custom.Add(axis);
axis.Automatic = false;
axis.Minimum = s.MinYValue();
axis.Maximum = s.MaxYValue();;
s.Visible = true;
axis.Visible = true;
axis.Increment = 2;
s.CustomVertAxis = axis;
if (tChart1.Series.Count != 1)
{
axis.RelativePosition = (-4) * (tChart1.Series.Count - 1);
}
axis.Visible = true;
}
Could you please check my code and adapt it, because we can reproduce your problem here to try to find a solution for you?
Thanks,
Re: How to add another series to chart.
Posted: Mon Jun 17, 2013 7:47 am
by 13049533
Hi Sandra,
Thanks for your reply,
I have seen your answer and i am trying to implement like that in my code but i have small doubt here.
Is it possible in the code which i have posted originally ,
in the above code i have several sensors response in the class of analogsensordata.
whenever he have new data from serial port he is raising this event and it is updating table as well as chart based on how many sensor i have connected.
which is working perfectly with the above code which i have posted previously.
what i want to know is, is it possible, I have another type of sensors and they have separate class than "AnalogSensorData " and i am trying to raise event when i have new data from serial port from these sensors.
i want to update these sensors values also to the same table and in the same chart like previous sensors. is it possible?
is it possible if i have two sensor information getting differently from serial port, i am trying to update both in same table and same chart. is it possible?
as well i am trying to implement your code, i understand your code but i need change some functions according to your code. i am trying to do that!
Re: How to add another series to chart.
Posted: Mon Jun 17, 2013 11:03 am
by 13049533
Hi,
I have tried to understand your code but i am confusing in the method
Code: Select all
private DataSet GetData(int i)
{........}
if you don't mine can you explain little bit about it. as well as can you add some chart image that how this code works.
Re: How to add another series to chart.
Posted: Mon Jun 17, 2013 12:17 pm
by 10050769
Hello biji,
I think is possible, but you need consider some items to implement a correct solution:
-You have to consider that you must define the values of table before populate the series dynamically or using a DataSource. To achieve it, you must implement methods or functions to get the data and update the table (UpdateTable) in the moment to get the values, to define the fields, after do it, you can already assign the Data to the series.
- If you want work with the separate class of sensor you must get the values of data and update your table in your AnalogSensorData class, because after you can assign data and update series, correctly.
-My code is a simple example that I have used to populate many series using a different datatables, to demonstrate as you need do to achieve as you want. In my case, I use GetData(int i) method to generate a data with different values for each series, where I have used i value as identifier by table and also I use i value to generate different x values.
If you have any problems to implement your application after my suggestions and code example. Please, try to arrange a simple code with DataTables with same parameters as you use by sensors, so we can work with a concretely example.
I hope will helps.
Thanks,
Re: How to add another series to chart.
Posted: Mon Jun 17, 2013 2:12 pm
by 13049533
Hi sandra,
thanks for your reply, I have tried your example i understand how you creating axis but in my application i am not able to use like that.
I am posting my code which updating the table with all sensor types. I have created some methods to update all sensors information. I have used only AnalogSenorData to update table and i have added some rows to update other sensors in the same method. Now i am able to update all sensors like that. Please can you have a look.
this will update all analog sensors(9 sensors). because whenever system name equal to specific sensor name then that eng value is updating.
I have updated with all variables. The above code is updating all values in the table correctly. If you don't understand then please ask me i will try to provide how much i can. I can say that time is the x-axis for all sensors. Is it possible to get the values from table based on column name or columnindex and keep updating in the chart. Column name is the name of sensor.
I have attached a simple image how table look likes.
Re: How to add another series to chart.
Posted: Tue Jun 18, 2013 11:28 am
by narcis
Hi biji,
Basically, what you need to do is associating new table values to the new TeeChart series you want to plot. You can either do it using the AnalogSensor class or outside of it. However, what you will need to do in both places is associating a data table field to a TeeChart series value list so that it can be plotted in a chart. You have edited your previous posts and removed the code but, if I remember correctly, this was done in the
UpdateChart method. So, what you'll have to do is something similar to existing sensors (data table fields) with your new sensors data. They need to be associated to a TeeChart series so they can be plotted in a chart.
If problems persist please try to arrange a simple example project, based on the
example code Sandra posted, using random data so that we can debug it here and hence provide an accurate reply.
Re: How to add another series to chart.
Posted: Mon Jun 24, 2013 8:27 am
by 13049533
Hi,
I have updated now, I have followed your suggestions and i added new line for each sensor class and it works fine but what happens is if i have different sensor groups then i need to add new line for each group and my code looks little bit ugly but anyhow thank you very much for helping me to solve this issue.
thanks.