本文整理汇总了C#中ZedGraph.GraphPane.AddPieSlice方法的典型用法代码示例。如果您正苦于以下问题:C# GraphPane.AddPieSlice方法的具体用法?C# GraphPane.AddPieSlice怎么用?C# GraphPane.AddPieSlice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZedGraph.GraphPane
的用法示例。
在下文中一共展示了GraphPane.AddPieSlice方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiPieChartDemo
public MultiPieChartDemo()
: base("A Demo of the MasterPane with Pie Charts",
"Multi-Pie Chart Demo", DemoType.General, DemoType.Special)
{
MasterPane myMaster = base.MasterPane;
// Remove the default GraphPane that comes with ZedGraphControl
myMaster.PaneList.Clear();
// Set the master pane title
myMaster.Title.Text = "Multiple Pie Charts on a MasterPane";
myMaster.Title.IsVisible = true ;
// Fill the masterpane background with a color gradient
myMaster.Fill = new Fill( Color.White, Color.MediumSlateBlue, 45.0F );
// Set the margins and the space between panes to 10 points
myMaster.Margin.All = 10;
myMaster.InnerPaneGap = 10;
// Enable the masterpane legend
myMaster.Legend.IsVisible = true ;
myMaster.Legend.Position = LegendPos.TopCenter;
myMaster.IsUniformLegendEntries = true;
// Enter some data values
double [] values = { 15, 15, 40, 20 } ;
double [] values2 = { 250, 50, 400, 50 } ;
Color [] colors = { Color.Red, Color.Blue, Color.Green, Color.Yellow } ;
double [] displacement = { .0,.0,.0,.0 } ;
string [] labels = { "East", "West", "Central", "Canada" } ;
// Create some GraphPanes
for ( int x=0; x<3; x++ )
{
// Create the GraphPane
GraphPane myPane = new GraphPane();
myPane.Title.Text = "2003 Regional Sales";
// Fill the pane background with a solid color
myPane.Fill = new Fill( Color.Cornsilk );
// Fill the axis background with a solid color
myPane.Chart.Fill = new Fill( Color.Cornsilk );
// Hide the GraphPane legend
myPane.Legend.IsVisible = false ;
// Add some pie slices
PieItem segment1 = myPane.AddPieSlice( 20, Color.Blue, .10, "North" );
PieItem segment2 = myPane.AddPieSlice( 40, Color.Red, 0, "South" );
PieItem segment3 = myPane.AddPieSlice( 30, Color.Yellow, .0, "East" );
PieItem segment4 = myPane.AddPieSlice( 10.21, Color.Green, .20, "West" );
PieItem segment5 = myPane.AddPieSlice( 10.5, Color.Aquamarine, .0, "Canada" );
segment1.LabelType = PieLabelType.Name_Value;
segment2.LabelType = PieLabelType.Name_Value;
segment3.LabelType = PieLabelType.Name_Value;
segment4.LabelType = PieLabelType.Name_Value;
segment5.LabelType = PieLabelType.Name_Value;
// Add the graphpane to the masterpane
myMaster.Add( myPane );
}
// Tell ZedGraph to auto layout the graphpanes
using ( Graphics g = this.ZedGraphControl.CreateGraphics() )
{
myMaster.SetLayout( g, PaneLayout.ExplicitRow12 );
myMaster.AxisChange( g );
//g.Dispose();
}
}
示例2: PieChart
/// <summary>
/// Creates a pie chart from a JSON request.
/// </summary>
/// <param name="query">Query batch.</param>
/// <param name="_options">GraphOptions.</param>
/// <param name="binaryOutput">if set to <c>true</c> the image will output in the response stream.</param>
/// <returns></returns>
public static System.Drawing.Bitmap PieChart( string query, Dictionary<string, object> _options, bool binaryOutput )
{
( "FUNCTION /w binaryStream pieChart" ).Debug( 10 );
/* query expects two columns
* 0 name
* 1 value
* 2 color1 (or null)
* 3 color2 (or null)
*/
JToken jtOpt = JToken.FromObject( _options );
JsonSerializer serializer = new JsonSerializer();
GraphOptions options = ( GraphOptions )serializer.Deserialize( new JTokenReader( jtOpt ), typeof( GraphOptions ) );
if( options.Width == 0 || options.Height == 0 ) {
/*bad image size defined */
return null;
}
System.Drawing.Bitmap image = null;
GraphPane myPane = null;
using(SqlConnection cn = Site.CreateConnection(true, true)) {
cn.Open();
try {
using(SqlCommand cmd = new SqlCommand(query, cn)) {
myPane = new GraphPane(new System.Drawing.Rectangle(0, 0, options.Width, options.Height), options.Title, "", "");
// Set the GraphPane title
myPane.Title.Text = options.Title;
myPane.Title.FontSpec.IsItalic = options.IsItalic;
myPane.Title.FontSpec.Size = options.TitleFontSize;
myPane.Title.FontSpec.Family = options.FontFamily;
System.Drawing.Color fill1 = System.Drawing.Color.FromName(options.Fill.StartColor);
System.Drawing.Color fill2 = System.Drawing.Color.FromName(options.Fill.EndColor);
// Fill the pane background with a color gradient
myPane.Fill = new Fill(fill1, fill2, options.Fill.Angle);
// No fill for the chart background
myPane.Chart.Fill.Type = FillType.None;
// Set the legend to an arbitrary location
myPane.Legend.IsVisible = options.ShowLegend;
myPane.Legend.Position = LegendPos.Float;
myPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top);
myPane.Legend.FontSpec.Size = 10f;
myPane.Legend.IsHStack = false;
List<PieItem> segments = new List<PieItem>();
using(SqlDataReader r = cmd.ExecuteReader()) {
while(r.Read()) {
System.Drawing.Color color1 = System.Drawing.Color.FromName(r.GetString(2));
System.Drawing.Color color2 = System.Drawing.Color.FromName(r.GetString(3));
PieItem s = myPane.AddPieSlice(Convert.ToDouble(r.GetValue(1)), color1, color2, 45f, 0, r.GetString(0));
if(r.GetValue(1).GetType() == typeof(decimal)) {
s.Label.Text = r.GetString(0) + ' ' + r.GetDecimal(1).ToString(options.NodeLabelFormat);
} else {
s.Label.Text = s.Label.Text = r.GetString(0) + ' ' + Convert.ToString(r.GetValue(1));
}
segments.Add(s);
}
}
}
// Sum up the pie values
CurveList curves = myPane.CurveList;
double total = 0;
for(int x = 0; x < curves.Count; x++)
total += ((PieItem)curves[x]).Value;
// Calculate the Axis Scale Ranges
myPane.AxisChange();
image = myPane.GetImage(true);
} catch(Exception ex) {
if(image == null) {
image = new Bitmap(700, 700);
}
image = WriteImageError(image, ex.Message, "Arial", 8f);
}
if(binaryOutput) {
using(MemoryStream ms = new MemoryStream()) {
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
if(HttpContext.Current != null) {
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "image/png";
HttpContext.Current.Response.AddHeader("Expires", "0");/* RFC 2616 14.21 Content has already expired */
HttpContext.Current.Response.AddHeader("Cache-Control", "no-store");/* RFC 2616 14.9.2 Don't ever cache */
HttpContext.Current.Response.AddHeader("Pragma", "no-store");/* RFC 2616 14.32 Pragma - same as cache control */
ms.WriteTo(HttpContext.Current.Response.OutputStream);
}
}
image.Dispose();
if(HttpContext.Current != null) {
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
return image;
}
示例3: lbt_importall_Click
//.........这里部分代码省略.........
HSSFWorkbook workbook = facade.InitializeWorkbook("杭州农副产品物流网络有限公司", logic.sysAdmin.AdminID.ToString(), "采购配送系统", "投诉管理");
Sheet sheet1 = workbook.CreateSheet("投诉详细");
facade.CreateRowHeader(workbook, sheet1, TimeRange + " 投诉列表", dtlist);
facade.FillRowData(workbook, sheet1, 2, dtlist, null, null, null, null);
Sheet sheet2 = workbook.CreateSheet("客户投诉");
facade.CreateRowHeader(workbook, sheet2, TimeRange + " 客户投诉情况", dtcompany);
facade.FillRowData(workbook, sheet2, 2, dtcompany, null, null, null, null);
Sheet sheet3 = workbook.CreateSheet("投诉汇总");
facade.CreateRowHeader(workbook, sheet3, TimeRange + " 投诉问题汇总", dtcomplaint);
facade.FillRowData(workbook, sheet3, 2, dtcomplaint, null, null, null, null);
#region 小类投诉情况
GraphPane graphpane = new GraphPane();
graphpane.Title.Text = "小类投诉情况";
graphpane.Title.FontSpec.Size = 12f;
graphpane.XAxis.Title.Text = "小类";
graphpane.XAxis.Title.FontSpec.Size = 11f;
graphpane.YAxis.Title.Text = ChangeStr("投诉数量");
graphpane.YAxis.Title.FontSpec.Angle = 90;
graphpane.YAxis.Title.FontSpec.Size = 11f;
graphpane.XAxis.IsVisible = true;
graphpane.YAxis.IsVisible = true;
List<string> category=new List<string>();
List<double> cnum = new List<double>();
int maxcnum = 2;
foreach (DataRow dr in dtcategory.Rows)
{
if(Convert.ToInt32( dr[1].ToString())>maxcnum)
maxcnum=Convert.ToInt32( dr[1].ToString());
category.Add(ChangeStr( dr[0].ToString()));
cnum.Add(Convert.ToDouble(dr[1].ToString()));
}
BarItem baritem = graphpane.AddBar(null,null,cnum.ToArray(), Color.Red);
baritem.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red);
BarItem.CreateBarLabels(graphpane, false, "f0");
graphpane.XAxis.Scale.TextLabels = category.ToArray();
graphpane.XAxis.Scale.Max = category.ToArray().Length+1;
graphpane.XAxis.Scale.MajorStep = 1;
graphpane.XAxis.MinorTic.Size = 0;
graphpane.XAxis.MajorTic.Size = 0;
graphpane.XAxis.Cross = 0;
graphpane.XAxis.Scale.FontSpec.Size = 10f;
graphpane.XAxis.Scale.FontSpec.Family = "宋体";
graphpane.XAxis.Type = AxisType.Text;
graphpane.XAxis.MajorTic.IsOutside = false;
graphpane.XAxis.MajorTic.IsOpposite = false;
graphpane.YAxis.Scale.Max = maxcnum+2;
graphpane.YAxis.MinorTic.Size = 0;
graphpane.YAxis.MinorGrid.DashOff = 0;
graphpane.YAxis.Scale.MajorStep = 1;
graphpane.YAxis.MajorTic.IsOpposite = false;
graphpane.YAxis.MajorTic.IsOutside = false;
graphpane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
graphpane.Fill = new Fill(Color.White, Color.FromArgb(250, 250, 255),45.0f);
graphpane.Fill.IsScaled = true;
MemoryStream ms = new MemoryStream();
//zgc.GetImage().Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
Bitmap map = graphpane.GetImage(750,550,17);
map.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] picbyte = ms.ToArray();
int index = workbook.AddPicture(picbyte, NPOI.SS.UserModel.PictureType.JPEG);
Sheet sheet4 = workbook.CreateSheet("小类投诉");
facade.CreateRowHeader(workbook, sheet4, TimeRange + " 小类投诉情况", dtcategory);
facade.FillRowData(workbook, sheet4, 2, dtcategory, null, null, null, null);
HSSFPatriarch hssfpatriarch = (HSSFPatriarch)sheet4.CreateDrawingPatriarch();
HSSFClientAnchor hssfanchor = new HSSFClientAnchor(0, 0, 0, 0, 4, 1, 18, 28);
HSSFPicture hssfpic = (HSSFPicture)hssfpatriarch.CreatePicture(hssfanchor, index);
#endregion
#region 部门投诉情况
GraphPane gp2 = new GraphPane();
gp2.Title.Text = "部门投诉情况";
gp2.XAxis.IsVisible = false;
gp2.YAxis.IsVisible = false;
gp2.Title.FontSpec.Size = 12f;
gp2.Fill = new Fill(Color.White);
gp2.Chart.Fill.Type = FillType.None;
gp2.Legend.Position = LegendPos.Float;
gp2.Legend.Location = new Location(0.95f, 0.08f, CoordType.PaneFraction, AlignH.Right, AlignV.Top);
gp2.Legend.FontSpec.Size = 10f;
gp2.Legend.IsHStack = false;
List<double> comnum=new List<double>();
List<string> dname=new List<string>();
foreach(DataRow dr in dtdepartment.Rows )
{
gp2.AddPieSlice(Convert.ToDouble(dr[1].ToString()), GetRandomColor(), 0, dr[0].ToString()+" ("+dr[1].ToString()+")").LabelType=PieLabelType.Percent;
}
Bitmap bitmap = gp2.GetImage(700, 700, 14);
MemoryStream mstream = new MemoryStream();
bitmap.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] buffer = mstream.ToArray();
int picindex = workbook.AddPicture(buffer, NPOI.SS.UserModel.PictureType.JPEG);
Sheet sheet5 = workbook.CreateSheet("部门投诉");
facade.CreateRowHeader(workbook, sheet5, TimeRange + " 责任部门投诉情况", dtdepartment);
facade.FillRowData(workbook, sheet5, 2, dtdepartment, null, null, null, null);
HSSFPatriarch patriarch = (HSSFPatriarch)sheet5.CreateDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, 4, 1, 15, 34);
HSSFPicture pic = (HSSFPicture)patriarch.CreatePicture(anchor, picindex);
#endregion
facade.ExportByWeb(workbook, TimeRange.ToString() + "采购配送系统投诉统计", TimeRange.ToString() + "采购配送系统投诉统计.xls");
}
示例4: GenerateDistributionGraphAndTable
private void GenerateDistributionGraphAndTable()
{
#region Write graph
GraphPane graphPane = new GraphPane(new Rectangle(0, 0, 512, 384), "", "", "");
graphPane.CurveList.Clear();
graphPane.Legend.Position = LegendPos.Right;
graphPane.Legend.IsVisible = false;
ArrayList groups = statsEngine.GetClusteredDataSet();
PieItem []segments = new PieItem[groups.Count];
for (int idx = 0; idx < groups.Count; idx++)
{
ArrayList items = groups[idx] as ArrayList;
string start = string.Format("{0:f2}", items[0]);
string end = string.Format("{0:f2}", items[items.Count-1]);
string label = start + " - " + end;
int colorseg = 255 - ((255 / groups.Count) * (idx+1));
segments[idx] = graphPane.AddPieSlice(items.Count, Color.FromArgb(colorseg, colorseg, colorseg), 0.0, label);
segments[idx].LabelDetail.FontSpec.Border.IsVisible = false;
segments[idx].LabelType = PieLabelType.Name_Value_Percent;
}
SaveGraphImage(graphPane, reportPath + @"\distribution.png");
#endregion
#region Write table
// write table header
distTable = new StringBuilder();
distTable.Append("<table><thead><tr>\n");
distTable.Append("<th width=\"20%\">Group</th>\n");
distTable.Append("<th width=\"20%\">Range in milliseconds</th>\n");
distTable.Append("<th width=\"20%\">Total tests</th>\n");
distTable.Append("<th width=\"20%\">Percent of total</th>\n");
distTable.Append("</tr></thead><tbody>\n");
int totalEntries = 0;
for (int i=0; i<groups.Count; i++)
{
ArrayList items = groups[i] as ArrayList;
totalEntries += items.Count;
}
bool oddline = true;
for (int i=0; i<groups.Count; i++)
{
ArrayList items = groups[i] as ArrayList;
string start = string.Format("{0:f2}", items[0]);
string end = string.Format("{0:f2}", items[items.Count-1]);
string label = start + " - " + end;
if (oddline == true)
distTable.Append("<tr class=\"odd\">\n");
else
distTable.Append("<tr class=\"even\">\n");
distTable.Append("<td class=\"s\">");
distTable.AppendFormat("{0}", i+1);
distTable.Append("</td>\n");
distTable.Append("<td class=\"s\">");
distTable.Append(label);
distTable.Append("</td>\n");
distTable.Append("<td class=\"s\">");
distTable.AppendFormat("{0}", items.Count);
distTable.Append("</td>\n");
double percent = 100 - (((double)(totalEntries - items.Count) / (double)totalEntries) * 100.0);
distTable.Append("<td class=\"s\">");
distTable.AppendFormat("{0:f2}", percent);
distTable.Append("</td>\n");
oddline = !oddline;
}
distTable.Append("</tr></table>\n");
#endregion
}
示例5: Form1_Load
//.........这里部分代码省略.........
master.Add( myPaneT );
Graphics g = this.CreateGraphics();
master.Title.IsVisible = false;
master.Margin.All = 0;
//master.AutoPaneLayout( g, PaneLayout.ExplicitRow32 );
//master.AutoPaneLayout( g, 2, 4 );
master.AutoPaneLayout( g );
//master.AutoPaneLayout( g, false, new int[] { 1, 3, 2 }, new float[] { 2, 1, 3 } );
master.AxisChange( g );
g.Dispose();
#endif
#if false // Pie
myPane = new GraphPane( new Rectangle( 10, 10, 10, 10 ),
"2004 ZedGraph Sales by Region\n($M)",
"",
"" );
myPane.FontSpec.IsItalic = true;
myPane.FontSpec.Size = 24f;
myPane.FontSpec.Family = "Times";
myPane.PaneFill = new Fill( Color.White, Color.Goldenrod, 45.0f );
myPane.Chart.Fill.Type = FillType.None;
myPane.Legend.Position = LegendPos.Float ;
myPane.Legend.Location = new Location( 0.95f, 0.15f, CoordType.PaneFraction,
AlignH.Right, AlignV.Top );
myPane.Legend.FontSpec.Size = 10f;
myPane.Legend.IsHStack = false;
PieItem segment1 = myPane.AddPieSlice( 20, Color.Navy, Color.White, 45f, 0, "North" );
PieItem segment3 = myPane.AddPieSlice( 30, Color.Purple, Color.White, 45f, .0, "East" );
PieItem segment4 = myPane.AddPieSlice( 10.21, Color.LimeGreen, Color.White, 45f, 0, "West" );
PieItem segment2 = myPane.AddPieSlice( 40, Color.SandyBrown, Color.White, 45f, 0.2, "South" );
PieItem segment6 = myPane.AddPieSlice( 250, Color.Red, Color.White, 45f, 0, "Europe" );
PieItem segment7 = myPane.AddPieSlice( 50, Color.Blue, Color.White, 45f, 0.2, "Pac Rim" );
PieItem segment8 = myPane.AddPieSlice( 400, Color.Green, Color.White, 45f, 0, "South America" );
PieItem segment9 = myPane.AddPieSlice( 50, Color.Yellow, Color.White, 45f, 0.2, "Africa" );
segment2.LabelDetail.FontSpec.FontColor = Color.Red ;
CurveList curves = myPane.CurveList ;
double total = 0 ;
for ( int x = 0 ; x < curves.Count ; x++ )
total += ((PieItem)curves[x]).Value ;
TextItem text = new TextItem( "Total 2004 Sales\n" + "$" + total.ToString () + "M",
0.18F, 0.40F, CoordType.PaneFraction );
text.Location.AlignH = AlignH.Center;
text.Location.AlignV = AlignV.Bottom;
text.FontSpec.Border.IsVisible = false ;
text.FontSpec.Fill = new Fill( Color.White, Color.FromArgb( 255, 100, 100 ), 45F );
text.FontSpec.StringAlignment = StringAlignment.Center ;
myPane.GraphItemList.Add( text );
TextItem text2 = new TextItem( text );
text2.FontSpec.Fill = new Fill( Color.Black );
text2.Location.X += 0.008f;
text2.Location.Y += 0.01f;
myPane.GraphItemList.Add( text2 );
myPane.AxisChange( this.CreateGraphics() );
#endif