Line chart - hide labels

Thread is closed for posting
7 posts, 0 answers
  1. JT
    JT avatar
    4 posts
    Member since:
    Apr 2011

    Posted 19 Apr 2011 Link to this post

    Hi,
    I am putting together a line chart to display data from a MSSQL database but cannot stop the numerical score labels from displaying. I have gone through all of the examples but need a little assistance. Please take a look at what I have and add what I need to stop the scores from rendering on the lines. I have attached images of existing render and table.
    I appreciate your time.

    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:IPdataConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT top 7 Date = CONVERT(char(10), Date, 101), score, IPaddress, Partner FROM IPhistory WHERE Partner = 'NEAstates' ORDER BY Date ASC;" runat="server">
    </asp:SqlDataSource>
                <telerik:radchart id="RadChart4" runat="server" width="800px" datasourceid="SqlDataSource1"
                    defaulttype="Line" autolayout="true" charttitle-visible="false">
                    <Appearance TextQuality="AntiAlias">
                    </Appearance>
                    <PlotArea>
                    <Appearance Dimensions-Margins="18%, 24%, 12%, 16%"></Appearance>
                        <YAxis Step="10" AxisMode="Extended">
                            <Appearance MajorGridLines-Visible="true" MinorGridLines-Visible="false">
                            </Appearance>
                        </YAxis>
                        <XAxis DataLabelsColumn="Date" LayoutMode="Between">
                            <Appearance ValueFormat="ShortDate" MajorGridLines-Visible="true">
                                <LabelAppearance RotationAngle="10" Position-AlignedPosition="Top">
                                </LabelAppearance>
                            </Appearance>
                        </XAxis>
                    </PlotArea>
                </telerik:radchart>

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // Manually setting the series groups and Y values columns
            RadChart4.DataGroupColumn = "IPaddress";
            RadChart4.DataManager.ValuesYColumns = new string[1] { "score" };
            RadChart4.Skin = "LightBlue";
            ChartSeries chartSeries = new ChartSeries();
            chartSeries.Type = ChartSeriesType.Line;
            chartSeries.Appearance.LabelAppearance.Visible = false;
        }
    }


  2. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 20 Apr 2011 Link to this post

    Hi JT,

    Have you tried chartSeries.Appearance.ShowLabels = False;
  3. JT
    JT avatar
    4 posts
    Member since:
    Apr 2011

    Posted 20 Apr 2011 Link to this post

    Hi Dean,
    Yes, I have tried every Label tag available. I am thinking it has something to do with RadChart rewriting the chartSeries but I do not think I have the new chartSeries setup to initialize properly.

    Thanks,
    _ JT
  4. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 21 Apr 2011 Link to this post

    Hi JT,

    Before the chart gets rendered and automatically generates the series for you, you will have to set the labels visibility for each series in your code-behind. Here is how you can achieve this,

    private void RadChart1_PreRender(object sender, System.EventArgs e)
    {
        Telerik.Web.UI.RadChart oChart = (Telerik.Web.UI.RadChart)sender;
        for (i = 0; i <= oChart.Series.Count - 1; i++) {
            oChart.Series.Item(i).Appearance.ShowLabels = false;
        }
    }
  5. JT
    JT avatar
    4 posts
    Member since:
    Apr 2011

    Posted 21 Apr 2011 Link to this post

    Thanks Dean,
    I see where you are going with the series setting but I am falling short on pluging it into my C# code-behind. I do not have any Items defined in the code I provided and am having difficulty getting it recognized. Is it possible to get my code enhanced with any additional modifications needed to get the PreRender to function. I appreciate your time.
  6. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 21 Apr 2011 Link to this post

    Hi JT,

    I've created a sample project with the same data you are using as well as the code you are using which I've modified allow the labels visibility to be false, please look at the sample project. I've uploaded it to a public area so you should be able to download it.

    Please notice the property in the ASP.NET Markup for the Chart_PreRender OnPreRender="RadChart4_PreRender"

    Excuse my c# code, I'm a vb developer.

    http://www.mediafire.com/?z2910uihx6lpwvf

    Hope this helps.
  7. JT
    JT avatar
    4 posts
    Member since:
    Apr 2011

    Posted 22 Apr 2011 Link to this post

    Hi Dean,
    That did the trick! I just had not cleaned out the old ChartSeries references when I added your PreRender script the other day.
    Good to go!

    Thanks,
    _ JT
Back to Top