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

How do i control visibility of a bar in radChart : Bar chart

1 Answer 136 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Ankush
Top achievements
Rank 1
Ankush asked on 24 Sep 2012, 04:09 PM
Hi
I need a help for i am unable to get anything to control the visibility for a bar in a bar chart.
Below is my code -
protected void SetAshGraph(RadChart RadChart, string bpAshValue, string apAshValue, string apTotSedi, string bpTotSedi, string ymax, string ymin, string steps, string title, string yaxislabel)
    {
        //------------------------------Setting Rad Chart Properties
        RadChart.Clear();
        RadChart.RemoveAllSeries();
        RadChart.Margins.Left = Unit.Percentage(25);
        RadChart.Margins.Bottom = Unit.Percentage(17);
        RadChart.Margins.Right = Unit.Percentage(10);
        RadChart.Title.Text = title;
        RadChart.Title.TextFont = new System.Drawing.Font("Verdana", 9, System.Drawing.FontStyle.Bold);
        RadChart.Title.Background.MainColor = Color.Transparent;
        RadChart.Title.Background.BorderColor = Color.Transparent;
        RadChart.Title.Background.FillStyle = FillStyle.Solid;
 
        //----------------------setting X porperties
 
        RadChart.XAxis.Clear();
        //RadChart.XAxis.Label.TextFont = new System.Drawing.Font("Verdana", 3, System.Drawing.FontStyle.Regular);
        //RadChart.XAxis.Items.Font = new System.Drawing.Font("Verdana", 2, System.Drawing.FontStyle.Regular);
         
        RadChart.XAxis.AddItem(""); //RadChart.XAxis.Items[0].Visible = false;
        //RadChart.XAxis.Items[0].Value = -1;
         
        RadChart.XAxis.AddItem("BP \nAsh");
        //RadChart.XAxis.Items[1].Value = 0;
 
        RadChart.XAxis.AddItem("AP \nAsh");
        //RadChart.XAxis.Items[2].Value = 1;
 
        RadChart.XAxis.AddItem(""); //RadChart.XAxis.Items[3].Visible = false;
        //RadChart.XAxis.Items[3].Value = -2;
 
        RadChart.XAxis.AddItem("BP \nTSA");
        //RadChart.XAxis.Items[4].Value = 2;
 
        RadChart.XAxis.AddItem("AP \nTSA");
        //RadChart.XAxis.Items[5].Value = 3;
 
        RadChart.BarOverlapPercent = 0; RadChart.BarWidthPercent = 100;
        RadChart.XAxis.AddItem("");
        //RadChart.XAxis.Items[6].Value = -3;
         
        //RadChart.XAxis.Items[6].Visible = false;
        RadChart.XAxis.AxisWidth = 1;
        RadChart.XAxis.AxisColor = Color.Black;
        RadChart.XAxis.Label.TextColor = Color.Black;
 
 
        //----------------------setting y porperties
        RadChart.YAxis.AddRange(double.Parse(ymin), double.Parse(ymax), double.Parse(steps));
        //   RadChart.YAxis.AutoScale = true;
        RadChart.YAxis.Label.Text = yaxislabel;
        RadChart.YAxis.Label.TextFont = new System.Drawing.Font("Verdana", 8, System.Drawing.FontStyle.Bold);
        RadChart.YAxis.AxisColor = Color.Black;
        RadChart.YAxis.Label.TextColor = Color.Black;
        RadChart.YAxis.AxisWidth = 1;
        RadChart.YAxis.DefaultItemColor = System.Drawing.Color.Black;
        //RadChart.YAxis.VisibleValues = ChartAxisVisibleValues.Positive;
        RadChart.XAxis.DefaultItemColor = System.Drawing.Color.Black;
        //RadChart.XAxis.VisibleValues = ChartAxisVisibleValues.Positive;
        //RadChart.XAxis.AutoScale = false;
        //RadChart.XAxis.AutoShrink = true;
         
         
        //------------------------------Adding  Chart series Properties
        ChartSeries s = RadChart.CreateSeries("Series", Color.DarkViolet, ChartSeriesType.Bar);
        s.Items.Series.Appearance.FillStyle = FillStyle.Solid;
        s.Items.Series.Appearance.BorderColor = Color.Black;
 
        ChartSeriesItem items0 = new ChartSeriesItem();
        items0.YValue = double.Parse(ymin); //items0.XValue = -1;
        s.Items.Add(items0);
        s.Items[0].Label = " ";
         
        //-----------------------------first Item i.e Bp/Ap reading
        ChartSeriesItem items1 = new ChartSeriesItem();
        double dd;
        if (double.TryParse(bpAshValue, out dd))
        {
            items1.YValue = dd;
            s.Items.Add(items1);
            //anks
            //s.Items[0].Appearance.MainColor = Color.FromArgb(153, 51, 101);
            //s.Items[0].Appearance.SecondColor = Color.FromArgb(153, 51, 101);
            s.Items[1].Appearance.MainColor = Color.FromArgb(198, 83, 138);
            s.Items[1].Appearance.SecondColor = Color.FromArgb(198, 83, 138);
            s.Items[1].Label = " ";
             
        }
        else
        {
            items1.YValue = dd;
            s.Items.Add(items1);
            s.Items[1].Label = " ";
        }
 
        ChartSeriesItem items2 = new ChartSeriesItem();
        if (double.TryParse(apAshValue, out dd))
        {
            items2.YValue = dd;
            s.Items.Add(items2);
            //anks
            //s.Items[1].Appearance.MainColor = Color.FromArgb(154, 153, 255);
            //s.Items[1].Appearance.SecondColor = Color.FromArgb(154, 153, 255);
            s.Items[2].Appearance.MainColor = Color.FromArgb(180, 179, 255);
            s.Items[2].Appearance.SecondColor = Color.FromArgb(180, 179, 255);
            s.Items[2].Label = " ";
        }
 
        ChartSeriesItem items3 = new ChartSeriesItem();
        items3.YValue = double.Parse(ymin); //items3.XValue = -2;
        s.Items.Add(items3);
        s.Items[3].Label = " ";
 
        ChartSeriesItem items4 = new ChartSeriesItem();
        if (double.TryParse(bpTotSedi, out dd))
        {
            items4.YValue = dd;
            s.Items.Add(items4);
            //anks
            //s.Items[2].Appearance.MainColor = Color.FromArgb(153, 51, 101);
            //s.Items[2].Appearance.SecondColor = Color.FromArgb(153, 51, 101);
            s.Items[4].Appearance.MainColor = Color.FromArgb(198, 83, 138);
            s.Items[4].Appearance.SecondColor = Color.FromArgb(198, 83, 138);
            s.Items[4].Label = " ";
        }
        ChartSeriesItem items5 = new ChartSeriesItem();
        if (double.TryParse(apTotSedi, out dd))
        {
            items5.YValue = dd;
            s.Items.Add(items5);
            //anks
            //s.Items[3].Appearance.MainColor = Color.FromArgb(154, 153, 255);
            //s.Items[3].Appearance.SecondColor = Color.FromArgb(154, 153, 255);
            s.Items[5].Appearance.MainColor = Color.FromArgb(180, 179, 255);
            s.Items[5].Appearance.SecondColor = Color.FromArgb(180, 179, 255);
            s.Items[5].Label = " ";
        }
        ChartSeriesItem items6 = new ChartSeriesItem();
        items6.YValue = double.Parse(ymin); //items6.XValue = -3;
        s.Items.Add(items6);
        s.Items[6].Label = " ";
 
        RadChart.AddChartSeries(s);
        //anks
        ChartSeries s1 = RadChart.CreateSeries("LineSeries", Color.Black, ChartSeriesType.Line);
        s1.Items.Series.Appearance.FillStyle = FillStyle.Solid;
        s1.Items.Series.Appearance.BorderColor = Color.Black;
        s1.Items.Series.ShowLabels = true;
        //RadChart.XAxis.LayoutStyle = ChartAxisLayoutStyle.Between;
        RadChart.XAxis.LayoutStyle = ChartAxisLayoutStyle.Normal;
         
        ChartSeriesItem LineItems0 = new ChartSeriesItem();
        if (double.TryParse(bpAshValue, out dd))
        {
            LineItems0.YValue = 1.5;
            s1.Items.Add(LineItems0);
            s1.Items[0].Appearance.MainColor = Color.Black;
            s1.Items[0].Label = "This is a strip line line li";
            s1.Items[0].Series.LabelAppearance.TextFont = new Font("Times New Roman", 9, FontStyle.Bold | FontStyle.Italic);
            s1.Items[0].Series.LabelAppearance.TextColor = Color.Black;
            //s1.Items[0].Series.LabelAppearance.TextColor = Color.Gold;
        }
        else
        {
            LineItems0.YValue = 1.5;
            s1.Items.Add(LineItems0);
            s1.Items[0].Label = " ";
        }
        ChartSeriesItem LineItems1 = new ChartSeriesItem();
        if (double.TryParse(bpAshValue, out dd))
        {
            LineItems1.YValue = 1.5;
            s1.Items.Add(LineItems1);
            s1.Items[1].Appearance.MainColor = Color.Black;
            s1.Items[1].Label = " ";
        }
        ChartSeriesItem LineItems2 = new ChartSeriesItem();
        if (double.TryParse(apAshValue, out dd))
        {
            LineItems2.YValue = 1.5;
            s1.Items.Add(LineItems2);
            s1.Items[2].Appearance.MainColor = Color.Black;
            s1.Items[2].Label = " ";
        }
        ChartSeriesItem LineItems3 = new ChartSeriesItem();
        if (double.TryParse(bpTotSedi, out dd))
        {
            LineItems3.YValue = 1.5;
            s1.Items.Add(LineItems3);
            s1.Items[3].Appearance.MainColor = Color.Black;
            s1.Items[3].Label = " ";
        }
        ChartSeriesItem LineItems4 = new ChartSeriesItem();
        if (double.TryParse(apTotSedi, out dd))
        {
            LineItems4.YValue = 1.5;
            s1.Items.Add(LineItems4);
            s1.Items[4].Appearance.MainColor = Color.Black;
            s1.Items[4].Label = " ";
        }
        ChartSeriesItem LineItems5 = new ChartSeriesItem();
        if (double.TryParse(apTotSedi, out dd))
        {
            LineItems5.YValue = 1.5;
            s1.Items.Add(LineItems5);
            s1.Items[5].Appearance.MainColor = Color.Black;
            s1.Items[5].Label = " ";
        }
        ChartSeriesItem LineItems6 = new ChartSeriesItem();
        if (double.TryParse(apTotSedi, out dd))
        {
            LineItems6.YValue = 1.5;
            s1.Items.Add(LineItems6);
            s1.Items[6].Appearance.MainColor = Color.Black;
            s1.Items[6].Label = " ";
        }
        RadChart.AddChartSeries(s1);
 
    }
and here is a graph in the attachment-

 I dont want the small bars that comes in the position 1st , 4th ,7th. But i need the space for them just without the small bars that comes in.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Sep 2012, 09:59 AM
Hi,

You can control the visibility of an item in barchart on ItemDataBound event of RadChart as follows.

C#:
protected void RadChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
{
  if (e.SeriesItem.YValue == 1.0)
  {
     e.SeriesItem.Visible = false;
  }
}

Thanks,
Princy.
Tags
Chart (Obsolete)
Asked by
Ankush
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or