Bars grouping one on another

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
jval
Posts: 40
Joined: Mon May 04, 2015 1:46 pm

Bars grouping one on another

Post by jval » Mon Aug 31, 2015 12:22 pm

Whether it is possible to place some series of bar with the same value of X.
That is, if there are points in a 3 series with values 10,20,30 that Y was to 30, but not the to 10+20+30, and we see only the third series?

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Bars grouping one on another

Post by ArctionPasi » Wed Sep 02, 2015 2:24 pm

Yes, possible, if I understood your question right.

Code: Select all

 m_chart.ViewXY.YAxes[0].SetRange(0, 60);

            int iBarWidth = 50;

            //NOTE: NEGATIVE BARWIDTH IN BARSPACING SETS THEM AT SAME POSITION 
            m_chart.ViewXY.BarViewOptions.BarSpacing = -iBarWidth;
            m_chart.ViewXY.BarViewOptions.Grouping = BarsGrouping.ByLocation; 

            
            int iPointCount = 3;
            double[] aYValues1 = new double[] { 10, 20, 30};
            double[] aYValues2 = new double[] { 25, 5, 15 };

            
            for (int iBar = 0; iBar < iPointCount; iBar++)
            {
                BarSeriesValue[] aData = new BarSeriesValue[2];
                aData[0].Value = aYValues1[iBar];
                aData[0].Location = 2;

                aData[1].Value = aYValues2[iBar];
                aData[1].Location = 6;

                //Set label text
                aData[0].Text = aYValues1[iBar].ToString("0");
                aData[1].Text = aYValues2[iBar].ToString("0");

                BarSeries bs = new BarSeries(m_chart.ViewXY, m_chart.ViewXY.XAxes[0], m_chart.ViewXY.YAxes[0]);

                bs.BarThickness = iBarWidth; 
                
                //Set series fill 
                bs.Fill.Color = DefaultColors.Series[iBar];
                bs.Fill.GradientColor = ChartTools.CalcGradient(DefaultColors.Series[iBar], Color.Black, 50);

                //Set label text style
                bs.LabelStyle.Angle = 0;
                bs.LabelStyle.VerticalAlign = BarsTitleVerticalAlign.BarTop;

                //Assign the values
                bs.Values = aData;

                m_chart.ViewXY.BarSeries.Add(bs);
            }

Like this, it renders 3rd series in front, overlapped, and doesn't put them side-by-side.
Bar chart
Bar chart
bars.jpg (139.52 KiB) Viewed 4890 times
LightningChart Support Team, PT

Post Reply