Click here to Skip to main content
15,891,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Experts,
I have to draw multiline chart. this chart will consist 3 lines for these 3 series I am taking 3 different table for preparing data. Individually I am getting line in chart but all together I am not getting. Please help me to find out where I am doing mistake in my code.

What I have tried:

1) Below is the design page aspx.
<pre lang="HTML"><pre><asp:Chart ID="Chart1" runat="server" Width="1059px">
                <Series>
                    <asp:Series Name="Series1" ChartType="Line" LegendText="Sap"></asp:Series>
                    </Series>

                     <Series>
                    <asp:Series Name="Series2" ChartType="Line" LegendText="Raildocs"></asp:Series>
                    </Series>

                     <Series>
                    <asp:Series Name="Series3" ChartType="Line" LegendText="RIC"></asp:Series>
                    </Series>
                <ChartAreas>
                    <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
                </ChartAreas>
            </asp:Chart>


2) Below is the code behind code .cs.

C#
public void ProDocs()
       {
           DataSet result = new DataSet();
           DataTable dtSap = new DataTable();
           DataTable dtRic = new DataTable();
           DataTable dtRailDocs = new DataTable();
           dtSap.Columns.Add("SapPlm", typeof(int));
           dtSap.Columns.Add("Date", typeof(DateTime));
           dtRailDocs.Columns.Add("RailDocs", typeof(int));
           dtRailDocs.Columns.Add("Date", typeof(DateTime));
           dtRic.Columns.Add("RIC", typeof(int));
           dtRic.Columns.Add("Date", typeof(DateTime));
           using (ProDocsEntities objcontext = new ProDocsEntities())
           {
               DateTime startDate = new DateTime(DateTime.Today.Year, 1, 1);
               for (int i = 1; i <= 53; i++)
               {
                   //DateTime startDate = new DateTime();
                  // DateTime endDate = new DateTime();

                     DateTime endDate = startDate.AddDays(7 - (int)(startDate.DayOfWeek));



                     var SapData = (from a in objcontext.FileProgresses
                                    join pg in objcontext.V01_PG on a.ProDocsId equals (int?)pg.ID into pgs
                                    from g in pgs.DefaultIfEmpty()
                                    join pr in objcontext.V01_PR on g.ID equals pr.PAGE into prs
                                    from p in prs.DefaultIfEmpty()
                                    where a.FullPath.Contains("2014KR0055") && (a.Received >= startDate && a.Received <= endDate) && (a.AvailableInProDocs != null)
                                    select new { a.Id, a.Downloaded, a.Unsupported, a.ProcessByAbbyy, a.AvailableInProDocs, a.AvailableInDocs2Go, a.LocDocMapping }).ToArray();
                   int SapCount = SapData.Count();
                   var RaildocsData = (from a in objcontext.FileProgresses
                                       join pg in objcontext.V01_PG on a.ProDocsId equals (int?)pg.ID into pgs
                                       from g in pgs.DefaultIfEmpty()
                                       join pr in objcontext.V01_PR on g.ID equals pr.PAGE into prs
                                       from p in prs.DefaultIfEmpty()
                                       where a.FullPath.Contains("2014KR0062") && (a.Received >= startDate && a.Received <= endDate) && (a.AvailableInProDocs != null)
                                       select new { a.Id, a.Downloaded, a.Unsupported, a.ProcessByAbbyy, a.AvailableInProDocs, a.AvailableInDocs2Go, a.LocDocMapping }).ToList();
                   int raildocCount = RaildocsData.Count();
                   var RicData = (from a in objcontext.FileProgresses
                                  join pg in objcontext.V01_PG on a.ProDocsId equals (int?)pg.ID into pgs
                                  from g in pgs.DefaultIfEmpty()
                                  join pr in objcontext.V01_PR on g.ID equals pr.PAGE into prs
                                  from p in prs.DefaultIfEmpty()
                                  where a.FullPath.Contains("2015KR0050") && (a.Received >= startDate && a.Received <= endDate) && (a.AvailableInProDocs != null)
                                  select new { a.Id, a.Downloaded, a.Unsupported, a.ProcessByAbbyy, a.AvailableInProDocs, a.AvailableInDocs2Go, a.LocDocMapping }).ToList();
                   int RicCount = RicData.Count();


                   dtSap.Rows.Add(SapCount, startDate);
                   dtRailDocs.Rows.Add(raildocCount,startDate);
                   dtRic.Rows.Add(RicCount,startDate);



                   startDate = endDate;

               }

                   Chart1.Series[1].XValueMember = "Date";
                   Chart1.Series[1].YValueMembers = "SapPlm";
                   Chart1.Series[1].Color = Color.Blue;
                   Chart1.DataSource = dtSap;



                   Chart1.Series[2].XValueMember = "Date";
                   Chart1.Series[2].YValueMembers = "SapPlm";
                   Chart1.DataSource = dtRailDocs;
                   Chart1.Series[2].Color = Color.Green;




                   Chart1.Series[3].XValueMember = "Date";
                   Chart1.Series[3].YValueMembers = "RIC";
                   Chart1.Series[3].Color = Color.Red;
                   Chart1.DataSource = dtRic;


           }
       }



Thanks in advance
Posted
Comments
Ralf Meier 13-Mar-17 7:08am    
If you want to have different Lines inside your Chart you should add your Data to the Series.
Perhaps it is also possible (you must try that) to add more than one DataTable to the Chart.DataSource - but what you are doing is to assign your DataTable to the Property ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900