none
How to remove spaces between columns in StackedColumn graph?

    Question

  • 1 private Dictionary<double[], Dictionary<stringint>> DiscoverXYAxisValues(double min, double max, DataTable dataRows,int columnIndex, int classIndex,out double step)  
    2         {  
    3             int defaultPairNumber = 7;  
    4             Dictionary<double[], Dictionary<stringint>> pairs = new Dictionary<double[], Dictionary<stringint>>(defaultPairNumber);  
    5             step = (max - min) / defaultPairNumber;  
    6  
    7             double x1 = min, x2 = 0.0;  
    8             int index = 0;  
    9  
    10             while (true)  
    11             {  
    12                 x2 = x1 + step;  
    13  
    14                 var found = from row in dataRows.AsEnumerable()  
    15                             where (double)row[columnIndex] >= x1 && (double)row[columnIndex] <= x2  
    16                             group row by row[classIndex] into grp1  
    17                             select new 
    18                             {  
    19                                 Class = grp1.Key,  
    20                                 Count = grp1.Count()                                  
    21                             };  
    22  
    23                 if (found.ToList().Count() > 0)  
    24                 {  
    25                     double[] key = new double[] { x1, x2 };  
    26                     Dictionary<stringint> value = new Dictionary<stringint>(found.Count());  
    27  
    28                     found.ToList().ForEach(item => value.Add(item.Class.ToString(), item.Count));  
    29  
    30                     pairs.Add(key, value);  
    31                     index++;  
    32                 }  
    33                 else 
    34                 {  
    35                     step = (max - min) / --defaultPairNumber;  
    36                     if (step >= max) break;  
    37  
    38                     x1 = min;  
    39                     index = 0;  
    40                     pairs.Clear();  
    41                     continue;  
    42                 }  
    43  
    44                 if (index >= defaultPairNumber) break;  
    45  
    46                 x1 = x2;  
    47             }  
    48  
    49             return pairs;  
    50         }  
    51  
    52         private List<Series> GenerateGraphData(int columnIndex, int classIndex, SeriesChartType chartType, DataProviderBase dataSource,out HashSet<object> XValues)  
    53         {  
    54               
    55             XValues = dataSource.GetColumnUniqueValues(columnIndex);  
    56             HashSet<object> ClassValues = dataSource.GetColumnUniqueValues(classIndex);  
    57  
    58             Dictionary<object,Series> dataSeries = new Dictionary<object,Series>();              
    59  
    60             DataTable data = dataSource.SampleData;  
    61             var rows = from row in data.AsEnumerable()  
    62                        select new { Class = row[classIndex], XValue = row[columnIndex] };  
    63             double step = 0.0;  
    64             Dictionary<double[], Dictionary<stringint>> xyValues = DiscoverXYAxisValues(Convert.ToDouble(XValues.Min()),  
    65                                                                                         Convert.ToDouble(XValues.Max()),  
    66                                                                                         dataSource.SampleData,  
    67                                                                                         columnIndex,  
    68                                                                                         classIndex,  
    69                                                                                         out step);  
    70  
    71             //Add graph series. Each distinct class value is a seperated series.  
    72             foreach (object obj in dataSource.GetColumnUniqueValues(classIndex))  
    73             {  
    74                 Series newSeries = new Series  
    75                 {  
    76                     Name = obj.ToString(),  
    77                     ChartType = chartType,  
    78                     IsValueShownAsLabel = true 
    79  
    80                 };  
    81                 newSeries["DrawSideBySide"] = "false";  
    82                 newSeries["PointWidth"] = "1.0";  
    83                 dataSeries.Add(obj, newSeries);                  
    84             }  
    85  
    86  
    87             foreach (KeyValuePair<double[], Dictionary<stringint>> val in xyValues)  
    88             {  
    89                 foreach (KeyValuePair<stringint> item in val.Value)  
    90                 {  
    91                     dataSeries[item.Key].Points.AddXY((val.Key[0] + val.Key[1]) / 2.0, item.Value);  
    92                 }  
    93             }  
    94  
    95             // Enable all elements  
    96             //MainChart.ChartAreas[0].AxisX.MinorGrid.Enabled = true;  
    97             //MainChart.ChartAreas[0].AxisX.MinorTickMark.Enabled = true;  
    98  
    99             // Set Grid lines and tick marks interval  
    100             //double MajorGrid_Interval = MainChart.ChartAreas[0].AxisX.MajorGrid.Interval = step;  
    101             //double MajorTickMark_Interval = MainChart.ChartAreas[0].AxisX.MajorTickMark.Interval = step;  
    102             //double MinorGrid_Interval = MainChart.ChartAreas[0].AxisX.MinorGrid.Interval = step / 10;  
    103             //double MinorTickMark_Interval = MainChart.ChartAreas[0].AxisX.MinorTickMark.Interval = step/10;  
    104               
    105  
    106             return dataSeries.Values.ToList();  
    107         }  
    108  
    109         private void GenerateGraph()  
    110         {  
    111             // Remove all series  
    112             MainChart.Series.Clear();  
    113  
    114             HashSet<object> XValues = null;  
    115             //  
    116             GenerateGraphData(0, selectedDataSource.ClassVariable, (SeriesChartType)Enum.Parse(typeof(SeriesChartType), GraphTypesCombo.SelectedItem.ToString(), true), selectedDataSource, out XValues).ForEach(s =>  MainChart.Series.Add(s));  
    117  
    118             MainChart.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(XValues.Max());  
    119             MainChart.ChartAreas[0].AxisX.Interval = (Convert.ToDouble((XValues.Max())) - Convert.ToDouble(XValues.Min())) / 2.0;  
    120             MainChart.ChartAreas[0].AxisX.Minimum = Convert.ToDouble(XValues.Min());  
    121  
    122             //StringBuilder series = new StringBuilder();  
    123             //for (int i = 0; i < MainChart.Series.Count; i++)  
    124             //{  
    125             //    series.Append(MainChart.Series[i].Name);  
    126             //    if (i < MainChart.Series.Count - 1)  
    127             //    {  
    128             //        series.Append(",");  
    129             //    }                  
    130             //}  
    131  
    132             MainChart.ChartAreas[0].RecalculateAxesScale();  
    133             MainChart.Update();  
    134         } 

    Hello everybody I'm trying to create a StackedColumn graph so to be able to achieve the representation of data in this way Weka Graph. For the graph generation I use exactly the same data with the previous example and till now my graph seems like that My Graph.

    But I am facing the following issues:

    1. I want to avoid spaces between column ranges(on the third column there is a space between the values 10 and 19).
    2. On the second column the blue series is hiding the values 1 and 5 which belong to different series.

    Below is the invoked code that creates my graph.

    Thanx in advanced

     

     


    C# Lover
    Tuesday, February 17, 2009 2:48 AM

Answers


  • Well I think I found the answer (but ofcourse I am not 100% sure). The steps I followed are described below:

    1) first a little padding with DataManipulator.InsertEmptyPoints (1, IntervalType.Number, "Iris-setosa,Iris-versicolor,Iris-virginica"); //interval set to 1 since the scale of Y-Axis is 1 

    2) then grouping with DataManipulator.Group("Y:SUM", 0.5, IntervalType.Number, "Iris-versicolor,Iris-virginica,Iris-setosa");// 0.5 interval for X-Axis

    The chart right now looks like this right now, which is exactly what I was trying to achieve... 

    And the final code looks like this...

    1        private void GenerateGraph() 
    2        { 
    3            // Remove all series 
    4            MainChart.Series.Clear(); 
    5 
    6            //insert series 
    7            MainChart.Series.Add("Iris-setosa"); 
    8            MainChart.Series.Add("Iris-versicolor"); 
    9            MainChart.Series.Add("Iris-virginica"); 
    10 
    11            foreach (Series s in MainChart.Series) 
    12            { 
    13                s.ChartType = SeriesChartType.StackedColumn; 
    14                s.IsValueShownAsLabel = true
    15                s.CustomProperties = "PointWidth=1.0"
    16                //s.CustomProperties = "EmptyPointValue=Average, DrawSideBySide=false, PointWidth = 1.0"; 
    17            } 
    18 
    19            //Insert data for Iris-setosa series 
    20            MainChart.Series["Iris-setosa"].Points.AddXY(4.55714285714286, 16); 
    21            MainChart.Series["Iris-setosa"].Points.AddXY(5.07142857142857, 24); 
    22            MainChart.Series["Iris-setosa"].Points.AddXY(5.58571428571429, 10); 
    23 
    24            //insert data for Iris-versicolor series 
    25            MainChart.Series["Iris-versicolor"].Points.AddXY(5.07142857142857, 5); 
    26            MainChart.Series["Iris-versicolor"].Points.AddXY(5.58571428571429, 19); 
    27            MainChart.Series["Iris-versicolor"].Points.AddXY(6.1, 15); 
    28            MainChart.Series["Iris-versicolor"].Points.AddXY(6.61428571428571, 9); 
    29            MainChart.Series["Iris-versicolor"].Points.AddXY(7.12857142857143, 2); 
    30 
    31            //insert data for Iris-virginica series 
    32            MainChart.Series["Iris-virginica"].Points.AddXY(5.07142857142857, 1); 
    33            MainChart.Series["Iris-virginica"].Points.AddXY(5.58571428571429, 5); 
    34            MainChart.Series["Iris-virginica"].Points.AddXY(6.1, 13); 
    35            MainChart.Series["Iris-virginica"].Points.AddXY(6.61428571428571, 16); 
    36            MainChart.Series["Iris-virginica"].Points.AddXY(7.12857142857143, 8); 
    37            MainChart.Series["Iris-virginica"].Points.AddXY(7.64285714285714, 6); 
    38 
    39            MainChart.ChartAreas[0].AxisX.Maximum = 7.9; 
    40            MainChart.ChartAreas[0].AxisX.Minimum = 4.3; 
    41            MainChart.ChartAreas[0].AxisX.Interval = (7.9 - 4.3) / 2.0; 
    42 
    43            MainChart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, "Iris-setosa,Iris-versicolor,Iris-virginica"); 
    44            MainChart.DataManipulator.Group("Y:SUM", 0.5, IntervalType.Number, "Iris-versicolor,Iris-virginica,Iris-setosa"); 
    45 
    46            //MainChart.Serializer.Save("C:\\Users\\alex\\ChartData.txt"); 
    47 
    48            MainChart.Update(); 
    49        } 


    C# Lover
    Thursday, February 19, 2009 3:15 PM

All replies

  • Does anyone has any ideas guys about the problems I am facing???!!!
    C# Lover
    Tuesday, February 17, 2009 5:27 PM
  • 1<Chart Size="687, 243"
    2  <Series> 
    3    <Series Name="Iris-setosa" Legend="Legend1" ChartType="StackedColumn" ChartArea="ChartArea1" IsValueShownAsLabel="True" CustomProperties="EmptyPointValue=Zero, DrawSideBySide=Auto, PointWidth=1.0"
    4      <Points> 
    5        <DataPoint XValue="4.55714285714286" YValues="16" /> 
    6        <DataPoint XValue="5.07142857142857" YValues="24" /> 
    7        <DataPoint XValue="5.58571428571429" YValues="10" /> 
    8      </Points> 
    9    </Series> 
    10    <Series Name="Iris-versicolor" Legend="Legend1" ChartType="StackedColumn" ChartArea="ChartArea1" IsValueShownAsLabel="True" CustomProperties="EmptyPointValue=Zero, DrawSideBySide=Auto, PointWidth=1.0"
    11      <Points> 
    12        <DataPoint XValue="5.07142857142857" YValues="5" /> 
    13        <DataPoint XValue="5.58571428571429" YValues="19" /> 
    14        <DataPoint XValue="6.1" YValues="15" /> 
    15        <DataPoint XValue="6.61428571428571" YValues="9" /> 
    16        <DataPoint XValue="7.12857142857143" YValues="2" /> 
    17      </Points> 
    18    </Series> 
    19    <Series Name="Iris-virginica" Legend="Legend1" ChartType="StackedColumn" ChartArea="ChartArea1" IsValueShownAsLabel="True" CustomProperties="EmptyPointValue=Zero, DrawSideBySide=Auto, PointWidth=1.0"
    20      <Points> 
    21        <DataPoint XValue="5.07142857142857" YValues="1" /> 
    22        <DataPoint XValue="5.58571428571429" YValues="5" /> 
    23        <DataPoint XValue="6.1" YValues="13" /> 
    24        <DataPoint XValue="6.61428571428571" YValues="16" /> 
    25        <DataPoint XValue="7.12857142857143" YValues="8" /> 
    26        <DataPoint XValue="7.64285714285714" YValues="6" /> 
    27      </Points> 
    28    </Series> 
    29  </Series> 
    30  <Legends> 
    31    <Legend Name="Legend1"
    32    </Legend> 
    33  </Legends> 
    34  <ChartAreas> 
    35    <ChartArea BorderColor="Transparent" Name="ChartArea1"
    36      <AxisY> 
    37        <MajorGrid IntervalOffset="Auto" IntervalOffsetType="Number" Interval="Auto" IntervalType="Number" /> 
    38        <MajorTickMark IntervalOffset="Auto" IntervalOffsetType="Number" Interval="Auto" IntervalType="Number" /> 
    39        <MinorTickMark Size="6" LineWidth="6" /> 
    40        <ScaleView Zoomable="False" /> 
    41      </AxisY> 
    42      <AxisX LineColor="Transparent" Interval="1.8000000000000003" IntervalOffsetType="Number" IntervalAutoMode="VariableCount" IsStartedFromZero="False" IsMarginVisible="False" Maximum="7.9" Minimum="4.3"
    43        <MajorGrid IntervalOffsetType="Number" IntervalType="Number" Enabled="False" /> 
    44        <MinorGrid Enabled="True" /> 
    45        <MajorTickMark IntervalOffset="Auto" IntervalOffsetType="Number" Interval="Auto" IntervalType="Number" /> 
    46        <MinorTickMark LineColor="Transparent" Enabled="True" /> 
    47        <ScaleView Zoomable="False" /> 
    48      </AxisX> 
    49    </ChartArea> 
    50  </ChartAreas> 
    51</Chart> 
    1private void GenerateGraph() 
    2        { 
    3            // Remove all series 
    4            MainChart.Series.Clear(); 
    5 
    6            //insert series 
    7            MainChart.Series.Add("Iris-setosa"); 
    8            MainChart.Series.Add("Iris-versicolor"); 
    9            MainChart.Series.Add("Iris-virginica"); 
    10 
    11            foreach (Series s in MainChart.Series) 
    12            { 
    13                s.ChartType = SeriesChartType.StackedColumn; 
    14                s.IsValueShownAsLabel = true
    15                s.CustomProperties = "EmptyPointValue=Zero, DrawSideBySide=Auto, PointWidth = 1.0"
    16            } 
    17 
    18            //Insert data for Iris-setosa series 
    19            MainChart.Series["Iris-setosa"].Points.AddXY(4.55714285714286, 16); 
    20            MainChart.Series["Iris-setosa"].Points.AddXY(5.07142857142857, 24); 
    21            MainChart.Series["Iris-setosa"].Points.AddXY(5.58571428571429, 10); 
    22 
    23            //insert data for Iris-versicolor series 
    24            MainChart.Series["Iris-versicolor"].Points.AddXY(5.07142857142857, 5); 
    25            MainChart.Series["Iris-versicolor"].Points.AddXY(5.58571428571429, 19); 
    26            MainChart.Series["Iris-versicolor"].Points.AddXY(6.1, 15); 
    27            MainChart.Series["Iris-versicolor"].Points.AddXY(6.61428571428571, 9); 
    28            MainChart.Series["Iris-versicolor"].Points.AddXY(7.12857142857143, 2); 
    29 
    30            //insert data for Iris-virginica series 
    31            MainChart.Series["Iris-virginica"].Points.AddXY(5.07142857142857, 1); 
    32            MainChart.Series["Iris-virginica"].Points.AddXY(5.58571428571429, 5); 
    33            MainChart.Series["Iris-virginica"].Points.AddXY(6.1, 13); 
    34            MainChart.Series["Iris-virginica"].Points.AddXY(6.61428571428571, 16); 
    35            MainChart.Series["Iris-virginica"].Points.AddXY(7.12857142857143, 8); 
    36            MainChart.Series["Iris-virginica"].Points.AddXY(7.64285714285714, 6); 
    37 
    38            MainChart.ChartAreas[0].AxisX.Maximum = 7.9; 
    39            MainChart.ChartAreas[0].AxisX.Minimum = 4.3; 
    40            MainChart.ChartAreas[0].AxisX.Interval = (7.9 - 4.3) / 2.0; 
    41 
    42            MainChart.ChartAreas[0].RecalculateAxesScale(); 
    43            MainChart.Update(); 
    44        } 


    Hello again,

    Well after a lot of responses about my previous post :) I decided to simplify a little bit my code in order to make one more try to have an answer this time. I have attached the method that generates my chart and the ChartData.txt file that contains the file created after calling the Chart1.Serializer.Save method.

    After trying the chart with the new code I receive exactly the same chart with this My Chart one. Remember that I am trying to remove the gaps between the column 3 and 4 in order to look like that Weka Chart, which means that I need to show the hidden values (1-5) in column 2 and remove all the gaps between columns and have a sequence as in columns 6-7.

    Above you can find the code and the chart data

    I would appreciate any suggestions

    In any case thanx a lot 


    C# Lover
    Tuesday, February 17, 2009 9:39 PM
  • Try removing the DrawSideBySide custom attribute  because it doesn't apply to stack charts, and set the PointWidth = 1.  Having the PointWidth set to 1.0 should not be any different, but I noticed in SSRS when I set it to 1.0 it changes it to "1", and I'm able to get it to work as you want.  It should work in the Chart control as well.

    -Sean
    Program Manager, SQL Server Reporting Services
    Tuesday, February 17, 2009 11:33 PM
  • 1        private void GenerateGraph() 
    2        { 
    3            // Remove all series 
    4            MainChart.Series.Clear(); 
    5 
    6            //insert series 
    7            MainChart.Series.Add("Iris-setosa"); 
    8            MainChart.Series.Add("Iris-versicolor"); 
    9            MainChart.Series.Add("Iris-virginica"); 
    10 
    11            foreach (Series s in MainChart.Series) 
    12            { 
    13                s.EmptyPointStyle.BorderWidth = s.BorderWidth; 
    14                s.ChartType = SeriesChartType.StackedColumn; 
    15                s.IsValueShownAsLabel = true
    16                s.CustomProperties = "PointWidth=1"
    17 
    18                s.EmptyPointStyle.BorderWidth = s.BorderWidth; 
    19                s.EmptyPointStyle.BorderDashStyle = s.BorderDashStyle; 
    20                s.EmptyPointStyle.BorderColor = s.BorderColor; 
    21                s.EmptyPointStyle.BackHatchStyle = s.BackHatchStyle; 
    22                s.EmptyPointStyle.BackGradientStyle = s.BackGradientStyle; 
    23 
    24                //s.CustomProperties = "EmptyPointValue=Average, DrawSideBySide=false, PointWidth = 1.0"; 
    25            } 
    26 
    27            //Insert data for Iris-setosa series 
    28            MainChart.Series["Iris-setosa"].Points.AddXY(4.55714285714286, 16); 
    29            MainChart.Series["Iris-setosa"].Points.AddXY(5.07142857142857, 24); 
    30            MainChart.Series["Iris-setosa"].Points.AddXY(5.58571428571429, 10); 
    31 
    32            //insert data for Iris-versicolor series 
    33            MainChart.Series["Iris-versicolor"].Points.AddXY(5.07142857142857, 5); 
    34            MainChart.Series["Iris-versicolor"].Points.AddXY(5.58571428571429, 19); 
    35            MainChart.Series["Iris-versicolor"].Points.AddXY(6.1, 15); 
    36            MainChart.Series["Iris-versicolor"].Points.AddXY(6.61428571428571, 9); 
    37            MainChart.Series["Iris-versicolor"].Points.AddXY(7.12857142857143, 2); 
    38 
    39            //insert data for Iris-virginica series 
    40            MainChart.Series["Iris-virginica"].Points.AddXY(5.07142857142857, 1); 
    41            MainChart.Series["Iris-virginica"].Points.AddXY(5.58571428571429, 5); 
    42            MainChart.Series["Iris-virginica"].Points.AddXY(6.1, 13); 
    43            MainChart.Series["Iris-virginica"].Points.AddXY(6.61428571428571, 16); 
    44            MainChart.Series["Iris-virginica"].Points.AddXY(7.12857142857143, 8); 
    45            MainChart.Series["Iris-virginica"].Points.AddXY(7.64285714285714, 6); 
    46 
    47            MainChart.ChartAreas[0].AxisX.Maximum = 7.9; 
    48            MainChart.ChartAreas[0].AxisX.Minimum = 4.3; 
    49            MainChart.ChartAreas[0].AxisX.Interval = (7.9 - 4.3) / 2.0; 
    50            //MainChart.Serializer.Save("C:\\Users\\alex\\ChartData.txt"); 
    51 
    52            MainChart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, "Iris-setosa,Iris-versicolor,Iris-virginica"); 
    53 
    54            foreach (Series s in MainChart.Series) 
    55            { 
    56                s.CustomProperties = "PointWidth=1"
    57            } 
    58 
    59            MainChart.ChartAreas[0].RecalculateAxesScale(); 
    60            MainChart.Update(); 
    61        } 

    Hello Sean thanx for your response. I tried your suggestions but nothing changed. But after a lot of searching I tried to use DataManipulator.InsertEmptyPoints which seems to work fine, check the new chart here but now another problem occured. 

    The PointWidth has changed and the series width is too thin now. I tried to change the PointWidth of the series again by writing this:

    foreach (Series s in MainChart.Series)
                {
                    s.CustomProperties = "PointWidth=1";
                }

    but without results. I have upload the new code.

    Thanx again

    C# Lover
    Wednesday, February 18, 2009 12:12 AM
  • I think part of the issue here is that the chart is inserting space along the axis to represent the points that you are not specifiying in your dataset.  This creates empty points, but empty point is actually not what you want here.  I'd remove any settings related to empty points.   I'm not able to try this directly at the moment, but you might want to try setting the IsXValueIndexed Property to True on the Series.  

    -Sean
    Program Manager, SQL Server Reporting Services
    Wednesday, February 18, 2009 4:39 AM
  • Hello Sean, well I believe that IsXValueIndexed has has no influence in my chart caused it is used when there is no Y value for an X value. I need exactly the results that I am getting from this chart right now. The only thing that I have to fix is the point width custom property which has been reset to an old value (is too thin) and can't bring the PointWidth=1.0 back. In other words I want to redraw my chart with the PointWidth property=1.0. If I find how to set the old width back I'll get an chart exactly like this.

    Thanx for your advices Sean

    C# Lover
    Wednesday, February 18, 2009 10:43 AM
  • Can you run ChartSerializer.Save and send us the XML file, or place it on a site like SkyDrive and we can pick it up, or paste the results here or you can contact me direclty via my blog at http://blogs.msdn.com/seanboon.  The problem with using the empty points is that when your axis is effectively a scalar axis, empty points are injected along the axis for each interval where you don't return data.  So if you're interval is 1, and you have 1,2,3,5 in your data set for X-values, then an empty point gets inserted at 4, which is exactly what you don't want.   I think in your case the X-values really represent categories which is why I was recommending setting the isXValueIndexed property to true.  At any rate, please send us the XML output and we'll take a look.

    -Sean


    Program Manager, SQL Server Reporting Services
    Wednesday, February 18, 2009 5:23 PM
  • <Chart Size="687, 243"
      <Series> 
        <Series Name="Iris-setosa" Legend="Legend1" IsXValueIndexed="True" ChartType="StackedColumn" ChartArea="ChartArea1" IsValueShownAsLabel="True" CustomProperties="PointWidth=1.0"
          <Points> 
            <DataPoint XValue="4.55714285714286" YValues="16" /> 
            <DataPoint XValue="5.07142857142857" YValues="24" /> 
            <DataPoint XValue="5.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="5.58571428571429" YValues="10" /> 
            <DataPoint XValue="6.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="7.55714285714286" YValues="0" IsEmpty="True" /> 
          </Points> 
        </Series> 
        <Series Name="Iris-versicolor" Legend="Legend1" IsXValueIndexed="True" ChartType="StackedColumn" ChartArea="ChartArea1" IsValueShownAsLabel="True" CustomProperties="PointWidth=1.0"
          <Points> 
            <DataPoint XValue="4.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="5.07142857142857" YValues="5" /> 
            <DataPoint XValue="5.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="5.58571428571429" YValues="19" /> 
            <DataPoint XValue="6.1" YValues="15" /> 
            <DataPoint XValue="6.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="6.61428571428571" YValues="9" /> 
            <DataPoint XValue="7.12857142857143" YValues="2" /> 
            <DataPoint XValue="7.55714285714286" YValues="0" IsEmpty="True" /> 
          </Points> 
        </Series> 
        <Series Name="Iris-virginica" Legend="Legend1" IsXValueIndexed="True" ChartType="StackedColumn" ChartArea="ChartArea1" IsValueShownAsLabel="True" CustomProperties="PointWidth=1.0"
          <Points> 
            <DataPoint XValue="4.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="5.07142857142857" YValues="1" /> 
            <DataPoint XValue="5.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="5.58571428571429" YValues="5" /> 
            <DataPoint XValue="6.1" YValues="13" /> 
            <DataPoint XValue="6.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="6.61428571428571" YValues="16" /> 
            <DataPoint XValue="7.12857142857143" YValues="8" /> 
            <DataPoint XValue="7.55714285714286" YValues="0" IsEmpty="True" /> 
            <DataPoint XValue="7.64285714285714" YValues="6" /> 
          </Points> 
        </Series> 
      </Series> 
      <Legends> 
        <Legend Name="Legend1"
        </Legend> 
      </Legends> 
      <ChartAreas> 
        <ChartArea BorderColor="Transparent" Name="ChartArea1"
          <AxisY> 
            <MajorGrid IntervalOffset="Auto" IntervalOffsetType="Number" Interval="Auto" IntervalType="Number" /> 
            <MajorTickMark IntervalOffset="Auto" IntervalOffsetType="Number" Interval="Auto" IntervalType="Number" /> 
            <MinorTickMark Size="6" LineWidth="6" /> 
            <ScaleView Zoomable="False" /> 
          </AxisY> 
          <AxisX LineColor="Transparent" Interval="1.8000000000000003" IntervalOffsetType="Number" IntervalAutoMode="VariableCount" IsStartedFromZero="False" IsMarginVisible="False" Maximum="7.9" Minimum="4.3"
            <MajorGrid IntervalOffsetType="Number" IntervalType="Number" Enabled="False" /> 
            <MinorGrid Enabled="True" /> 
            <MajorTickMark IntervalOffset="Auto" IntervalOffsetType="Number" Interval="Auto" IntervalType="Number" /> 
            <MinorTickMark LineColor="Transparent" Enabled="True" /> 
            <ScaleView Zoomable="False" /> 
          </AxisX> 
        </ChartArea> 
      </ChartAreas> 
    </Chart> 

    Hello again Sean, well when I try to use IsXValueIndexed I am getting this exception:

    Cannot display indexed series (XValueIndexed = true) on the same axis if they are not aligned.Series 'Iris-setosa' and Series 'Iris-versicolor' must be aligned to perform the operation. The series currently have a different number of data points.

    which is expected because using XValueIndexed requires ALL series to be aligned see this link for more info taken from Dundas. 

    But what I am saying is that here I need to resolve the missing data of Y-axis not for X-Axis, the IsXValueIndexed property removes all the unused points for X-Axis. In my data sample I have all the X-Axis data available. To be more spesific thats what exactly the algorithm, I posted in my first post, does (please check at the begging of this post). I find dynamically the ranges for X-axis (values between 4.3-7.9) and for each range I place the range median (x2-x1/2) as the X value. For each of this ranges my algorithm finds the frequency for each of the series. For example on this chart at column 4 on X-axis we have the value 6,1 for this X I have found that 13 items belongs to series Iris-Virginica (with Red color) and 15 items belongs to Iris-versicolor  series (with orange color) which is absolutely correct, is exactly what I want to do. But in this case the problem was the spaces on column 3 and 4 which I resolved using the InsertEmptyPoints method and then my chart looks like that which is absolutely correct but has an appearance problem... is too thin  ofcourse :) so I tried to reset to PointWidth property to 1.0 but nothing changes. So the last chart contains exactly the data I want but should set the PointWidth=1.0.

    In any case I am sending the data I receive from Serializer.Save again

    Thanx a lot Sean

    C# Lover
    Wednesday, February 18, 2009 6:34 PM

  • Well I think I found the answer (but ofcourse I am not 100% sure). The steps I followed are described below:

    1) first a little padding with DataManipulator.InsertEmptyPoints (1, IntervalType.Number, "Iris-setosa,Iris-versicolor,Iris-virginica"); //interval set to 1 since the scale of Y-Axis is 1 

    2) then grouping with DataManipulator.Group("Y:SUM", 0.5, IntervalType.Number, "Iris-versicolor,Iris-virginica,Iris-setosa");// 0.5 interval for X-Axis

    The chart right now looks like this right now, which is exactly what I was trying to achieve... 

    And the final code looks like this...

    1        private void GenerateGraph() 
    2        { 
    3            // Remove all series 
    4            MainChart.Series.Clear(); 
    5 
    6            //insert series 
    7            MainChart.Series.Add("Iris-setosa"); 
    8            MainChart.Series.Add("Iris-versicolor"); 
    9            MainChart.Series.Add("Iris-virginica"); 
    10 
    11            foreach (Series s in MainChart.Series) 
    12            { 
    13                s.ChartType = SeriesChartType.StackedColumn; 
    14                s.IsValueShownAsLabel = true
    15                s.CustomProperties = "PointWidth=1.0"
    16                //s.CustomProperties = "EmptyPointValue=Average, DrawSideBySide=false, PointWidth = 1.0"; 
    17            } 
    18 
    19            //Insert data for Iris-setosa series 
    20            MainChart.Series["Iris-setosa"].Points.AddXY(4.55714285714286, 16); 
    21            MainChart.Series["Iris-setosa"].Points.AddXY(5.07142857142857, 24); 
    22            MainChart.Series["Iris-setosa"].Points.AddXY(5.58571428571429, 10); 
    23 
    24            //insert data for Iris-versicolor series 
    25            MainChart.Series["Iris-versicolor"].Points.AddXY(5.07142857142857, 5); 
    26            MainChart.Series["Iris-versicolor"].Points.AddXY(5.58571428571429, 19); 
    27            MainChart.Series["Iris-versicolor"].Points.AddXY(6.1, 15); 
    28            MainChart.Series["Iris-versicolor"].Points.AddXY(6.61428571428571, 9); 
    29            MainChart.Series["Iris-versicolor"].Points.AddXY(7.12857142857143, 2); 
    30 
    31            //insert data for Iris-virginica series 
    32            MainChart.Series["Iris-virginica"].Points.AddXY(5.07142857142857, 1); 
    33            MainChart.Series["Iris-virginica"].Points.AddXY(5.58571428571429, 5); 
    34            MainChart.Series["Iris-virginica"].Points.AddXY(6.1, 13); 
    35            MainChart.Series["Iris-virginica"].Points.AddXY(6.61428571428571, 16); 
    36            MainChart.Series["Iris-virginica"].Points.AddXY(7.12857142857143, 8); 
    37            MainChart.Series["Iris-virginica"].Points.AddXY(7.64285714285714, 6); 
    38 
    39            MainChart.ChartAreas[0].AxisX.Maximum = 7.9; 
    40            MainChart.ChartAreas[0].AxisX.Minimum = 4.3; 
    41            MainChart.ChartAreas[0].AxisX.Interval = (7.9 - 4.3) / 2.0; 
    42 
    43            MainChart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, "Iris-setosa,Iris-versicolor,Iris-virginica"); 
    44            MainChart.DataManipulator.Group("Y:SUM", 0.5, IntervalType.Number, "Iris-versicolor,Iris-virginica,Iris-setosa"); 
    45 
    46            //MainChart.Serializer.Save("C:\\Users\\alex\\ChartData.txt"); 
    47 
    48            MainChart.Update(); 
    49        } 


    C# Lover
    Thursday, February 19, 2009 3:15 PM
  • Monday, May 02, 2011 2:07 PM