This is a migrated thread and some comments may be shown as answers.

Can't show X-axis item labels on line chart

2 Answers 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gerald
Top achievements
Rank 1
Gerald asked on 21 Jul 2009, 01:38 PM
Hello,

I have a line chart in my report and want to show dates on the x-axis. Unfortunately the X-axis item labels don't show up. I tried to do it with the following code:

 

private void _gideonChart_NeedDataSource(object sender, EventArgs e)

 

{

_gideonChart.Series.Clear();

_gideonChart.PlotArea.XAxis.Clear();

_gideonChart.PlotArea.XAxis.AutoScale =

false;

 

_gideonChart.PlotArea.XAxis.AutoShrink =

false;

 

 

ChartSeries msciUsdSeries = new ChartSeries();

 

msciUsdSeries.Name =

"MSCI World USD";

 

msciUsdSeries.Type =

ChartSeriesType.Line;

 

msciUsdSeries.Appearance.FillStyle.MainColor =

Color.Purple;

 

msciUsdSeries.Appearance.FillStyle.SecondColor =

Color.Purple;

 

 

ChartSeries msciEurSeries = new ChartSeries();

 

msciEurSeries.Name =

"MSCI World EUR";

 

msciEurSeries.Type =

ChartSeriesType.Line;

 

msciEurSeries.Appearance.FillStyle.MainColor =

Color.FromArgb(203, 216, 254);

 

msciEurSeries.Appearance.FillStyle.SecondColor =

Color.FromArgb(203, 216, 254);

 

 

foreach (var entry in _dataSource)

 

{

 

ChartSeriesItem msciUsdItem = new ChartSeriesItem();

 

 

ChartSeriesItem msciEurItem = new ChartSeriesItem();

 

msciUsdItem.YValue = (

double)entry.MsciUsdQuote;

 

msciUsdItem.Label.Visible =

false;

 

msciUsdSeries.Items.Add(msciUsdItem);

msciEurItem.YValue = (

double)entry.MsciEurQuote;

 

msciEurItem.Label.Visible =

false;

 

msciEurSeries.Items.Add(msciEurItem);

 

ChartAxisItem chartAxisItem = new ChartAxisItem(entry.QuotesDate.Date.ToShortDateString());

 

_gideonChart.PlotArea.XAxis.AddItem(chartAxisItem);

}

_gideonChart.Series.Add(msciUsdSeries);

_gideonChart.Series.Add(msciEurSeries);

}

If you see some mistakes or know something else that might help, please let me know.

Thanks in advance and kind regards,
Gerald

2 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 23 Jul 2009, 11:25 AM
Hi Gerald,

Your code looks correct and we've used similar code to test this on our end:

  private void _gideonChart_NeedDataSource(object sender, EventArgs e) 
        { 
            _gideonChart.PlotArea.XAxis.AutoScale = false
            _gideonChart.PlotArea.XAxis.Clear(); 
 
            ChartSeries series = new ChartSeries(); 
            series.Type = ChartSeriesType.Line; 
 
            _gideonChart.Series.Add(series); 
            for (int i = 0; i < 10; i++) 
            { 
                series.AddItem(new ChartSeriesItem(i)); 
                _gideonChart.PlotArea.XAxis.AddItem(new ChartAxisItem(DateTime.Today.AddDays(i).ToShortDateString())); 
                _gideonChart.PlotArea.Appearance.Dimensions.Margins.Bottom.Value = 30; 
                _gideonChart.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 90; 
            } 
        } 

As you can see we alter two additional properties - RotationAngle and BottomMargin. We do this so that the actual labels are clearly visible. If this is your problem, please try playing around with them and let us know of the outcome.

Best wishes,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Gerald
Top achievements
Rank 1
answered on 23 Jul 2009, 11:51 AM
Thank you very much, Steve.
You pointed into the right direction. After your confirmation that the code is correct I inspected the appearance settings via Designer and I could find the problem.

Best regards, Gerald
Tags
General Discussions
Asked by
Gerald
Top achievements
Rank 1
Answers by
Steve
Telerik team
Gerald
Top achievements
Rank 1
Share this question
or