I am admittedly new to this, but after much reading I am stumped how to get the data from my stored procedure to appear on a scatter chart within UltraChart.
Here is what I am doing. Just sample data I made up. THE REAL DATA WILL COME FROM A STORED PROCEDURE. If that makes a difference
Here is where I have created a sql datasource in Visual Studio and select the table above
Next I set the UltraChart datasource to be the Sql datasource above
Now it this point when i ran it it crashed. Here is the message
Then I went in to the Chart Wizard and added a chart area and two axes. Here I set the X-axis
Then set Y
And then at least when I ran it it did not crash, but no data was shown. See below.
How do i connect my X data with the X-axis and Y-data with the Y-axis? Can I do it in the wizard or do I have to do it in the code?
Please also keep in mind this is all just test data trying to get anything to work. The actual data will be coming from a stored procedure whose output looks like this
TIA for your help.
I think you should replace the ScatterLine chart with a scatter chart or a composite chart with scatter and line layers. If you only intend to use the lines as control limits, I suggest a regular scatter chart with a little bit of drawing magic in the FillSceneGraph event. Here's a sample that should give you a very similar output to the first chart image:private void Form1_Load(object sender, EventArgs e){ DataTable dt = new DataTable(); dt.Columns.Add("ScatterX", typeof(int)); dt.Columns.Add("ScatterY", typeof(int));
dt.Rows.Add(new object[] { 0, 3 }); dt.Rows.Add(new object[] { 1, 6 }); dt.Rows.Add(new object[] { 2, 9 }); dt.Rows.Add(new object[] { 3, 5 }); dt.Rows.Add(new object[] { 4, 3 }); dt.Rows.Add(new object[] { 5, 2 });
ultraChart1.ChartType = ChartType.ScatterChart; ultraChart1.ScatterChart.ColumnX = 0; ultraChart1.ScatterChart.ColumnY = 1; ultraChart1.Axis.X.TickmarkStyle = AxisTickStyle.Smart; ultraChart1.Axis.Y.TickmarkStyle = AxisTickStyle.Smart;
ultraChart1.Axis.Y.RangeMin = 0; ultraChart1.Axis.Y.RangeMax = 10; ultraChart1.Axis.Y.RangeType = AxisRangeType.Custom;
ultraChart1.DataSource = dt;
ultraChart1.FillSceneGraph += new Infragistics.UltraChart.Shared.Events.FillSceneGraphEventHandler(ultraChart1_FillSceneGraph);}
void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e){ if (e.Grid.Count == 0) return;
double min = e.ChartCore.GetChartLayer().GetData().GetDataMinColumn(1); double max = e.ChartCore.GetChartLayer().GetData().GetDataMaxColumn(1);
IAdvanceAxis xAxis = (IAdvanceAxis)e.Grid["X"]; IAdvanceAxis yAxis = (IAdvanceAxis)e.Grid["Y"];
Line UCL = new Line(); UCL.p1 = new Point((int)xAxis.MapMinimum, (int)yAxis.Map(max)); UCL.p2 = new Point((int)xAxis.MapMaximum, (int)yAxis.Map(max)); UCL.PE.Stroke = Color.Red; UCL.PE.StrokeWidth = 3;
Line LCL = new Line(); LCL.p1 = new Point((int)xAxis.MapMinimum, (int)yAxis.Map(min)); LCL.p2 = new Point((int)xAxis.MapMaximum, (int)yAxis.Map(min)); LCL.PE.Stroke = Color.Red; LCL.PE.StrokeWidth = 3;
e.SceneGraph.Add(UCL); e.SceneGraph.Add(LCL);}
Let me try this differently. Let me show you what I want to create with a scatterline chart. I have created a demo data table.
This is what I would like it to come out as:
With another similar, yet different set of data trying to feed the scatterline diagram with only one line on top of the scatter data I get this:
I read Charts 101 on this site and it said using an external datasource could cause the scatterline chart to be funky. So far I agree.
I can get the data arranged anyway I need it. Can someone tell me how to get the chart I am looking for?
Hey Max,
Thanks very much for the reply. Since I posted this I kept at it reading all over your site here. I managed to make it run, but would appreciate running what I found past you for confirmation.
In my case I was trying the most simple thing possible to create a scatter; I created a SQL table with 3 columns labels, X, and Y. I plopped a single UltraWebChart on the page all alone. I set the datasource to the SQL table and set the chart type to scatter. I wanted to see if I could make the chart work without adding any code at all.
After much trial and error here is what I found
It seems to agree with your reply above. Does all that sound correct?
Now I am actually moving on to the ultimate goal of a scatterline diagram. So far I know I need to do a composite chart and have been successful at recreating the wizard example located here http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Chart_Creating_a_Composite_Chart.html
I want to take the output of a single stored procedure to do a scatter plot using the first two numric columns and then use subsequent columns to plot the upper and lower control limits. By now I am thinking I can just goto the chart and select that stored procedure as the datasource, but I am going to have to use code to tell the chart what columns to use for the UCL and LCL lines.
Am I on the right track? Any pointers you might have to help? I am about as green with this stuff as someone can be. I am very happy to take any help offered :)
You can stick with your original approach of assigning the sql datasource directly to the chart.You just have to set two additional properties for it to work:chart.ScatterChart.ColumnX = 0chart.ScatterChart.ColumnY = 1
By default the chart will look for numeric data in columns 1 and 2, but yours is in columns 0 and 1. This should fix the error.