Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Control barspacing in bar chart
posted

I need barspacing to be half of the width of bars in Barchart. When I am trying to assign a value to Barspace it takes integer value and assigning 1 makes the barspace space equal to bar width.

Please suggest how I can make barspace = 0.5 * Bar width.

Thanks

Parents
No Data
Reply
  • 17605
    posted

    You can set the BarSpacing and SeriesSpacing to 0 and correct the height of the bars in the ChartDrawItem event. Try using this code:

    this.UltraChart1.ChartType = ChartType.BarChart;

            this.UltraChart1.BarChart.BarSpacing = 0;

            this.UltraChart1.BarChart.SeriesSpacing = 0;

     

            UltraChart1.DataSource = DemoTable.AllPositive();

            UltraChart1.DataBind();

     

            this.UltraChart1.ChartDrawItem += UltraChart1_ChartDrawItem;

    private void UltraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e)

        {

            Box box = e.Primitive as Box;

            if (box == null || box.DataPoint == null)

            {

                return;

            }

     

            int diff = (int)(box.rect.Height / 6.0);

     

            box.rect.Y += diff;

            box.rect.Height -= 2 * diff;

        }

Children
No Data