Prev: Cpu Utilization
Next: 10 random numbers from 0 to 20
From: Tony Johansson on 15 Jun 2010 05:04 Hello! If I want to draw a pie with the data in the paremeterless Draw method below and I want to specify a specific color for each sector in the piechart how can that be done. There is no overloaded method in the PieChartElement class where I can add a color object. The other Draw method is an event handler for the Paint event for a PictureBox. The method called DrawPieChart is where the actual drawing take place. As you can see in this code I pass all the data except the color for each sector in the pie chart to method DrawPieChart but I want to also pass the color for each sector. //event handler for the Picurebox private void Draw(object sender, PaintEventArgs e) { Draw(); } private void Draw() { ArrayList data = new ArrayList(); data.Add(new PieChartElement("East", (float)50.75)); data.Add(new PieChartElement("West", (float)22)); data.Add(new PieChartElement("North", (float)72.32)); data.Add(new PieChartElement("South", (float)12)); data.Add(new PieChartElement("Central", (float)44)); chart.Image = DrawPieChart(data, new Size(chart.Width, chart.Height)); } //Tony
From: Peter Duniho on 15 Jun 2010 11:14 Tony Johansson wrote: > Hello! > > If I want to draw a pie with the data in the paremeterless Draw method below > and I want to specify a specific color for each sector in the piechart how > can that be done. There is no overloaded method in the PieChartElement class > where I can add a color object. The other Draw method is an event handler > for the Paint event for a PictureBox. > The method called DrawPieChart is where the actual drawing take place. > > As you can see in this code I pass all the data except the color for each > sector in the pie chart to method DrawPieChart but I want to also pass the > color for each sector. Since DrawPieChart() and PieChartElement() are not .NET features, they must be either some third-party library you're using or code you've written. If they are a library, then go talk to the author of the library to have them add the features you want. If it's your own code, then add the features you want yourself. Also, it is folly to bother handling the Paint event for your "chart" object, as well as to handle it by calling a method that does nothing at all with the data provided by the event (not even caring about the sender). Given the design you've presented here, you should not use the Paint event at all. Just redraw the pie chart when the data changes, and assign the resulting Image to the PictureBox's Image property. Finally, if you have control over the DrawPieChart() method, or if it will accept some type other than ArrayList (e.g. it only requires IEnumerable) don't use ArrayList. Use List<PieChartElement> instead. Pete
|
Pages: 1 Prev: Cpu Utilization Next: 10 random numbers from 0 to 20 |