c# - ASP.NET Chart Control and Databinding to multiple Series


Question: 

I am working with the ASP.NET chart control and I am using the following code to databind data to the chart control. The chart has three series on it: Series1, Series2 and Series3. The problem that I am having with the code below is that it only seems to bind to the first series so that when the chart is displayed, only the first series (Series1) shows, the other two do not display. If I step through he code everything seems to be fine.

Does anyone have any suggestions as to a solution to this issue?

private void ChartData1()
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["someConnectionString"].ConnectionString;

            SqlCommand cmd = null;
            cmd = new SqlCommand("dbo.ChartData", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Codevalue", SqlDbType.VarChar, 12);
            cmd.Parameters.Add("@filter", SqlDbType.VarChar, 50);

            cmd.Parameters["@Codevalue"].Value = "JAM";
            cmd.Parameters["@filter"].Value = "three_letter_code";

            conn.Open();
            SqlDataReader chartReader = cmd.ExecuteReader();

            //Bind the data using the DataBindTable method
            this.Chart1.Series["Series1"].Points.DataBindXY(chartReader, "bucketdate", chartReader, "RecordCount");
            this.Chart1.Series["Series2"].Points.DataBindXY(chartReader, "bucketdate", chartReader, "AverageTurns");
            this.Chart1.Series["Series3"].Points.DataBindXY(chartReader, "bucketdate", chartReader, "MovingAverageTurns");

            chartReader.Close();
            conn.Close();
        }

    }



1 Answer: 

A reader is forward only, your code as it stands would need to iterate through the reader three times.

There are a number of options, but if you want to use DataBindXY, you will need to extract the data from the reader into a collection (e.g. using LINQ) and bind to that collection.

An alternative would be to set the XValueMember and YValueMembers properties on each series, then call DataBind which would then bind all three series in one iteration through the reader.

 

More Articles


configuration - PhpStorm configure to work remotely

Hi is there a way for PhpStorm to work directly on a remote server? No local files. Because as of the moment PhpStorm has local files wherein it just automatically uploads all files during save on remote.My problem is if someone changes something remotely I need to manually download it first before

c# - WindowsForm app with wpf windows is not working on other computers

I'm new to WPF and c# programming,i have built a winform app with a database and some wpf forms.wpf forms contain some background images and componentone tab controls.To add wpf forms:i added a wpf user control and modified its code as a window.in that case i m unable to put background images from u

android - How to get a progress bar under the ActionBar in Material Design?

The Material Design specifications for Progress and activity specifically show in several areas a horizontal progress indicator of only a few pixels (dips) thick below whatever it is we are calling the ActionBar these days (probably Toolbar).However, I don't see any way to actually implement that po


wpf - Canvas control is not available in Windows form application?

WPF Canvas control is not available in Windows form application. Am using Visual Studio 2010. Framework 4.0. Is there way to add these controls to VS2010 toolbox?

material design - android lollipop toolbar: how to hide/show the toolbar while scrolling?

I'm using the new toolbar widget introduced in the appcompat / support-v7. I would like to hide/show the toolbar depending on if the user is scrolling up/down the page, just like in the new Google's playstore app or NewsStand app. Is there something built into the toolbar widget for this or should I

How to disable version control in phpstorm?

I am playing around with phpstorm and somehow I activated version control. I don't need it. Now all my tabs are different: orange text on gray background. All files in the file view are orange. How do I disable version control?


Keras autoencoder outputting wrong shape

I'm trying to build a deep convolutional autoencoder in Keras, but it keeps outputting the wrong shape.Code: def build_network(input_shape): input_input = Input(shape=input_shape) #Encode x = Conv2D(16, (3, 3), activation='relu', padding = 'same')(input_input) x = MaxPooling2D((2, 2), p

phpStorm show changed/modififed files in project view

After moving from Zend Studio (ZS) to phpStorm I am starting to miss the way that ZS used to show changed files and display more than one project at once. E.g: notice how the IndexController.php shows that this has been modified. Is there anyway to do this with phpStorm?

AttributeError: 'NoneType' object has no attribute '_inbound_nodes' in Autoencoders in Keras

I am not able to solve the following error, please accept my apologies if it sounds naive, I am very new to Keras.The output of the encoder is actually a complex value, so each output is real and imaginary part, input_h1 is also a complex value with real and imaginary parts represented as a vector.

c# - MVVM Bind to Page.DataContext from TabControl

I'm structuring my WPF application using MVVM Light and am creating the ViewModel using the IOC.The page initializes its DataContext like this:DataContext="{Binding Main, Source={StaticResource Locator}}"A TabControl has its content bound to another ViewModel, so binding from within the TabControl w