Profile Picture

Gantt Chart or Stached Horizontal bar

Posted By Hans Henrik Friis Pedersen... 9 Years Ago
Author
Message
Hans Henrik Friis Pedersen...
Question Posted 9 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 28, Visits: 136
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 

Nevron Support
Posted 9 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 1:54 AM
Posts: 3,054, Visits: 4,009
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.




Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic