Nevron Forum

Gantt Chart or Stached Horizontal bar

https://www.nevron.com/Forum/Topic8903.aspx

By Hans Henrik Friis Pedersen - Monday, January 19, 2015

Hi,

I would like to make a chart similar to the attached photo. I think I can make something similar to this using a stacked horizontal bars but:

1) There are approx. 125 "many colored" rectangles in one bar. Does that mean I have to make 125 series of a bar in order t make this chart?

2) How do I control the colors so that a rectangle of barseries1 is red in one bar but yellow in another bar? For instance, the very first rectangle is green at the bar at the top but blue at the third highest bar - How do I control this if I'm using the same barseries?https://www.nevron.com/forum/uploads/images/731ed9ec-ea3f-49b1-8c7b-15ee.png 
By Nevron Support - Monday, January 19, 2015

Hi Hans,

You can control the filling of each bar using the FillStyles series of bar - for example:

   NChart chart = nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();

   bar.Values.Add(10);
   bar.FillStyles[0] = new NColorFillStyle(Color.Red);

   bar.Values.Add(20);
   bar.FillStyles[1] = new NColorFillStyle(Color.Green);

   bar.Values.Add(30);
   bar.FillStyles[2] = new NColorFillStyle(Color.Blue);

   chart.Series.Add(bar);

Creates three bars with different colors. An alternative approach to this chart will be to use bars with mapped image fill that is generated so that it represents the color stripes you want. For example:

   NChart chart = nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();

   bar.Values.Add(10);

   chart.Series.Add(bar);

   chart.SetPredefinedChartStyle(PredefinedChartStyle.HorizontalLeft);

   chart.Axis(StandardAxis.PrimaryY).UpdateScale();

   Bitmap bmp = new Bitmap(1, 1024, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

   for (int i = 0; i < 1024; i++)
   {
    bmp.SetPixel(0, i, Color.FromArgb(i % 255, i % 255, i % 255));
   }

   NImageFillStyle imgFill = new NImageFillStyle(bmp);
   imgFill.TextureMappingStyle.MapMode = MapMode.RelativeToObject;
   imgFill.TextureMappingStyle.MapLayout = MapLayout.Stretched;
   bar.FillStyle = imgFill;

Creates a bar series with four white to black stripes. Hope this helps - let us know if you have any questions or meet any problems.