Click here to Skip to main content
15,896,512 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
Hi,
i have a stackbar devexpress chart control in my web page. i want to show data count by month. now i want to show two bar for different size value based on database. currently my chart only shows one bar per month.



http://demos.devexpress.com/XTRACHARTSDEMOS/BarViewTypes/BarStackedSideBySideSeries.aspx[^]


this is something what i want to achieve. but my graph only shows one bar per month. i am binding data dynamic to the series in the chart control, here is my code.

ASP.NET
  <dxchartsui:WebChartControl ID="WebChartControl4" style="box-shadow:3px 3px 3px #999;"  runat="server" Height="300px"
        Width="600px" ClientInstanceName="chart" 
        
        CrosshairEnabled="False" ToolTipEnabled="False" PaletteName="Nature Colors" 
                  SideBySideEqualBarWidth="false">
        <legend antialiasing="True"></legend>
      <%--  <Titles>
            <dxcharts:ChartTitle Text="Movement Chart" ></dxcharts:ChartTitle>
            
        </Titles>--%>
        <SeriesSerializable>
          
        
        </SeriesSerializable>
      
   
                              <DiagramSerializable>
<dxcharts:XYDiagram>
<AxisX Title-Text="Month" VisibleInPanesSerializable="-1">
<Range SideMarginsEnabled="True"    ></Range>
</AxisX>
<AxisY Title-Text="Count" Title-Visible="True" VisibleInPanesSerializable="-1" Interlaced="True">
<Range SideMarginsEnabled="True"></Range>
</AxisY>
</dxcharts:XYDiagram>
</DiagramSerializable>
        <BorderOptions Visible="True" />
    </dxchartsui:WebChartControl>





C#
List<DataTable> dt  = CloneTable(objRes.ResultData.Tables[0], 12);
               WebChartControl4.Series.Clear();
               for (int i = 0; i < dt.Count; i++)
               {
                   Series s = new Series(dt[i].Rows[0][2].ToString(), ViewType.SideBySideStackedBar);

                   DataView dv = dt[i].DefaultView;
                   dv.Sort = "ID ASC";
                    dt[i] = dv.ToTable();
                   s.DataSource = dt[i];
                   s.ArgumentDataMember = dt[i].Columns[0].ColumnName;
                   s.ValueDataMembers.AddRange(new string[] { dt[i].Columns[1].ColumnName });

                   s.LegendPointOptions.PointView = PointView.Argument;
                   s.ShowInLegend = true;
                   s.LabelsVisibility = DefaultBoolean.True;
                   s.Label.ResolveOverlappingMode = ResolveOverlappingMode.HideOverlapped;

                   WebChartControl4.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
                   WebChartControl4.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
                   WebChartControl4.Series.Add(s);
                   ((SideBySideStackedBarSeriesView)s.View).BarDistanceFixed = 5;
                   if (i % 2 == 0)
                   {

                       GroupSeries(i, "0");
                   }
                   else
                   {
                       GroupSeries(i, "1");
                   }


                   WebChartControl4.Legend.Visible = true;




               }


   void GroupSeries(int seriesIndex, string group)
       {
           if (seriesIndex < WebChartControl1.Series.Count)
           {
               ISupportStackedGroup view = WebChartControl1.Series[seriesIndex].View as ISupportStackedGroup;
               if (view != null)
                   view.StackedGroup = group;
           }
       }


i got 12 tables based on 6 status * two different size as per my need. i bind this 12 series from c#. please let me know if you have some idea.
Posted

1 solution

You have mentioned chart id as ID="WebChartControl4"

and in the GroupSeries method you are using "WebChartControl1".

Make it WebChartControl4.

Hope it helps :)
 
Share this answer
 
Comments
ravikhoda 28-Apr-14 9:29am    
Thank you so much this help me a lot. i spent my entire day on this one. + 5.

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