Adding BarWidthPercent programmatically

Thread is closed for posting
3 posts, 0 answers
  1. Larevenge
    Larevenge avatar
    38 posts
    Member since:
    Jul 2009

    Posted 12 Apr 2010 Link to this post

    Sorry, posted it in the wrong forum, ASP.NET instead of ASP.NET AJAX, however the question was:

    Im trying to make a RadChart with dynamic series, which are added from the code behind. Beneath i have the code server side with a dynamic added serie to the radchart:

            private void InitRadChart() 
            { 
                RadChart1.ChartTitle.TextBlock.Text = "Pensioen overzicht"
     
                RadChart1.Chart.Series.Clear(); 
                RadChart1.PlotArea.XAxis.AutoScale = false
                RadChart1.PlotArea.XAxis.AddRange(intPrePensioenLeeftijd, intEindeXAsLeeftijd, 1); 
     
                int intHuidigInkomenRest = intHuidigInkomen%5000; 
     
                RadChart1.PlotArea.YAxis.AutoScale = false
                RadChart1.PlotArea.YAxis.AddRange(0, intHuidigInkomen-intHuidigInkomenRest+10000 , 5000); 
     
     
                ChartSeries csPrePensioen = new ChartSeries("PrePensioen", ChartSeriesType.StackedBar); 
                int intPPAOWGerechtigdeLeeftijd = intAOWGerechtigdeLeeftijd; 
                int intPPPrePensioenLeeftijd = intPrePensioenLeeftijd; 
                csPrePensioen.ActiveRegionToolTip = "test"
                csPrePensioen.Appearance.BarWidthPercent = 100; 
     
                for (int i = intPPPrePensioenLeeftijd; i < intPPAOWGerechtigdeLeeftijd; i++) 
                { 
                    ChartSeriesItem citem = new ChartSeriesItem(); 
                     
                    citem.XValue = i; 
                    citem.YValue = intPrepensioen; 
                    csPrePensioen.AddItem(citem); 
                } 
                csPrePensioen.Appearance.LabelAppearance.Visible = false
                RadChart1.Series.Add(csPrePensioen); 
     
        } 

    Here is the code of the RadChart:

    <telerik:RadChart ID="RadChart1" runat="server" Skin="Metal" Height="400px" Width="700px"
        <PlotArea> 
            <EmptySeriesMessage Visible="True"
                <Appearance Visible="True"
                </Appearance> 
            </EmptySeriesMessage> 
            <XAxis> 
                <Appearance Color="Transparent" MajorTick-Color="174, 174, 174"
                    <MajorGridLines Color="40, 255, 255, 255" PenStyle="Solid" /> 
                    <TextAppearance TextProperties-Color="51, 51, 51"
                    </TextAppearance> 
                </Appearance> 
                <AxisLabel> 
                    <TextBlock> 
                        <Appearance TextProperties-Color="51, 51, 51"
                        </Appearance> 
                    </TextBlock> 
                </AxisLabel> 
                <Items> 
                    <telerik:ChartAxisItem Value="100"
                    </telerik:ChartAxisItem> 
                </Items> 
            </XAxis> 
            <YAxis> 
                <Appearance Color="Transparent" MajorTick-Color="174, 174, 174" MinorTick-Color="174, 174, 174"
                    <MajorGridLines Color="40, 255, 255, 255" /> 
                    <MinorGridLines Color="40, 255, 255, 255" /> 
                    <TextAppearance TextProperties-Color="51, 51, 51"
                    </TextAppearance> 
                </Appearance> 
                <AxisLabel> 
                    <TextBlock> 
                        <Appearance TextProperties-Color="51, 51, 51"
                        </Appearance> 
                    </TextBlock> 
                </AxisLabel> 
            </YAxis> 
            <Appearance Corners="Round, Round, Round, Round, 4"
                <FillStyle FillType="Image"
                    <FillSettings BackgroundImage="{plotarea}" ImageAlign="Top" ImageDrawMode="Flip" 
                        ImageFlip="FlipY"
                    </FillSettings> 
                </FillStyle> 
                <Border Color="174, 174, 174" Width="4" /> 
            </Appearance> 
        </PlotArea> 
        <Appearance Corners="Round, Round, Round, Round, 10"
            <FillStyle FillType="Image"
                <FillSettings ImageDrawMode="Flip" BackgroundImage="{chart}"
                </FillSettings> 
            </FillStyle> 
            <Border Color="111, 111, 111"></Border> 
        </Appearance> 
        <ChartTitle> 
            <Appearance> 
                <FillStyle MainColor="Transparent"
                </FillStyle> 
            </Appearance> 
            <TextBlock> 
                <Appearance TextProperties-Font="Arial, 16pt"
                </Appearance> 
            </TextBlock> 
        </ChartTitle> 
        <Legend> 
            <Appearance Position-AlignedPosition="TopRight" Dimensions-Margins="16%, 3%, 1px, 1px"
                <ItemTextAppearance TextProperties-Color="Black"
                </ItemTextAppearance> 
                <FillStyle MainColor="Transparent"
                </FillStyle> 
                <Border Color="Transparent"></Border> 
            </Appearance> 
        </Legend> 
    </telerik:RadChart> 
     
    Whatever i try, the barwidthpercent can't be set from the code behind, the bars keep a distance between each other.

    I can't see what im doing wrong either, whenever i try to make a serie in the client side, the barwidthpercent does work, but the problem of that is that i cant dynamicly add series to the chart, depending on how much i need. Any solution?

    thanks in advance


  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 15 Apr 2010 Link to this post

    Hello Larevenge,

    I can see my suggestion in the other thread has done the trick. Just for the sake of completeness and in case anyone else stumbles upon the same problem -- the solution is to use the global property:

    RadChart1.Appearance.BarWidthPercent = 100;

    Kind regards,
    Ves
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Travis
    Travis avatar
    226 posts
    Member since:
    Jan 2003

    Posted 04 May 2011 Link to this post

    Hmm, global setting didn't work for me.  I had to iterate through each series on the PreRender event and set the

    Appearance.BarWidthPercent for each series.

Back to Top