0

I have 2 problems:

  1. I want the names from the datatable but it is showing me in numeric form.

  2. I would like a gap between the two bars but I can't find a way.

Here is the code:

private void InitializeGraph (DataTable poDt) { Telerik.Charting.ChartSeries chartseries = new Telerik.Charting.ChartSeries();

    try
    {


        chartseries.Type = Telerik.Charting.ChartSeriesType.Bar;

        Telerik.Charting.ChartSeriesItem csItem;

        RadChart1.PlotArea.XAxis.AutoScale = true;
        RadChart1.PlotArea.XAxis.DataLabelsColumn = "Name";


        for (int iRow = 0; iRow < poDt.Rows.Count; iRow++)
        {
            chartseries = new Telerik.Charting.ChartSeries();

            chartseries.Type = Telerik.Charting.ChartSeriesType.Bar;

            chartseries.Name = poDt.Rows[iRow]["Name"].ToString().Trim();


            csItem = new Telerik.Charting.ChartSeriesItem();
            csItem.Name = poDt.Rows[iRow]["Name"].ToString();
            csItem.Label.TextBlock.Text = poDt.Rows[iRow]["Value"].ToString(); 
            RadChart1.PlotArea.XAxis.Appearance.TextAppearance.AutoTextWrap = Telerik.Charting.Styles.AutoTextWrap.True;

            csItem.YValue = Int32.Parse(poDt.Rows[iRow]["Value"].ToString());

            chartseries.AddItem(csItem);
            RadChart1.Series.Add(chartseries);

        }
        RadChart1.PlotArea.XAxis.AddRange(1, poDt.Rows.Count, 1);

        RadChart1.PlotArea.XAxis[poDt.Rows.Count].TextBlock.Text = chartseries.Name;
        poDt.Rows.Count.ToString();
        RadChart1.PlotArea.XAxis.AutoShrink = false;


        RadChart1.PlotArea.XAxis.AutoShrink = true;
        RadChart1.Series.Add(chartseries);

        RadChart1.PlotArea.Appearance.Border.Visible = false;
        RadChart1.Appearance.Border.Visible = true;
        RadChart1.PlotArea.YAxis.IsLogarithmic = true;

        RadChart1.PlotArea.YAxis.AutoScale = true;
        RadChart1.PlotArea.YAxis.Appearance.ValueFormat=Telerik.Charting.Styles.ChartValueFormat.Number;
        RadChart1.Appearance.BarWidthPercent = 50;



        RadChart1.Chart.Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
        RadChart1.Chart.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;
        RadChart1.Legend.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;

    }
    catch (Exception Ex)
    {
        //throw;
    }
    finally
    {
        poDt.Clear();
        poDt = null;
        chartseries = null;
    }
}
VRJ
  • 1
  • 4

1 Answers1

0

Sorry, I do not believe there is a way to display two X-axis at the same time.

My suggestion is you use a CategoricalAxis for your X axis and create a custom bar chart that has a legend which differentiates the two values. I don't have any working samples, however you can use this Telerik Silverlight demo for starters.

Also, switch to RadChartView if you can. Because I would then suggest an easier approach, which is using a Categorical X-Axis and create multiple Y axes. If you go that route, you can do something like this for a DateTimeContinuous (or Categorical) X-axis with multiple Y-axes :

int count = 0;
LineSeries lineSeries = new LineSeries();

lineSeries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "TimeStamp" };
lineSeries.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Value" };  

lineSeries.VerticalAxis = new LinearAxis()
{
   Title = "Title Here"
};

lineSeries.ItemsSource = yourCollection.Values;

//First Y-axis to be placed on the left of X-axis,
//additional Y-axes to be placed on right
if (count > 0 )
{
     lineSeries.VerticalAxis.HorizontalLocation = Telerik.Charting.AxisHorizontalLocation.Right;
}
count++;
chartName.Series.Add(lineSeries);

Hope this helps.

Kcvin
  • 5,073
  • 2
  • 32
  • 54
  • Actually i don't want two x-axis i wanted two values on x-axis planned and Actual – VRJ Jan 09 '13 at 04:27
  • look at the Silverlight example I provided. The closest thing you're going to get is what the graph in the top left of the demo looks like. It might help if you provide what your current code is doing or/and a screenshot of what it looks like and what you want it to look like. – Kcvin Jan 09 '13 at 15:07
  • I am not able to upload the picture of my graph its giving me error – VRJ Jan 10 '13 at 04:47
  • do a Print Screen and then Ctrl + V in Paint. Save it as an image, then go to imgur.com and upload it there. provide the URL on here. – Kcvin Jan 10 '13 at 16:36
  • I'm sorry but I don't believe that will be possible. You only have a few choices of types of an axis and the closest fit for you would be a CategoricalAxis. There would be no way to create seperate labels since everything would be either Planned or Actual. – Kcvin Jan 11 '13 at 14:38