using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZedGraph;
namespace ZedGraphDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ShowChart2();
}
private void ShowChart1()
{
zedGraphControl1.GraphPane.CurveList.Clear();
zedGraphControl1.GraphPane.GraphObjList.Clear();
GraphPane myPane = zedGraphControl1.GraphPane;
myPane.Title.Text = "消费者学历统计"; //设计图表的标题
myPane.XAxis.Title.Text = "学历类型";//X轴标题
myPane.YAxis.Title.Text = "人数";//Y轴标题
PointPairList PPLa = new PointPairList();
PointPairList PPLb = new PointPairList();
PointPairList PPLc = new PointPairList();
PointPairList PPLd = new PointPairList();
for (int i = 1; i < 5; i++)
{
PPLa.Add(i, i + 3);
PPLb.Add(i, i + 4);
PPLc.Add(i, i + 5);
PPLd.Add(i, i + 6);
}
BarItem myBara = myPane.AddBar("A", PPLa, Color.Red);
BarItem myBarb = myPane.AddBar("B", PPLb, Color.Blue);
BarItem myBarc = myPane.AddBar("C", PPLc, Color.Gray);
BarItem myBard = myPane.AddBar("D", PPLd, Color.Black);
zedGraphControl1.AxisChange();
zedGraphControl1.Refresh();
}
private void ShowChart2()
{
zedGraphControl1.GraphPane.CurveList.Clear();
zedGraphControl1.GraphPane.GraphObjList.Clear();
GraphPane myPane = zedGraphControl1.GraphPane;
myPane.Title.Text = "消费者学历统计"; //设计图表的标题
myPane.XAxis.Title.Text = "学历类型";//X轴标题
myPane.YAxis.Title.Text = "人数";//Y轴标题
PointPairList PPLa = new PointPairList();
PointPairList PPLb = new PointPairList();
PointPairList PPLc = new PointPairList();
PointPairList PPLd = new PointPairList();
for (int i = 1; i <= 5; i++)
{
PPLa.Add(i, i + 3);
PPLb.Add(i, i + 4);
PPLc.Add(i, i + 5);
PPLd.Add(i, i + 6);
}
BarItem myBara = myPane.AddBar("A", PPLa, Color.Red);
BarItem myBarb = myPane.AddBar("B", PPLb, Color.Blue);
BarItem myBarc = myPane.AddBar("C", PPLc, Color.Gray);
BarItem myBard = myPane.AddBar("D", PPLd, Color.Black);
string[] labels = { "产品1", "产品2", "产品3", "产品4", "产品5" };
myPane.XAxis.Scale.TextLabels = labels;
myPane.XAxis.Type = AxisType.Text;
//图区以外的颜色
myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f);
//背景颜色
myPane.Chart.Fill = new Fill(Color.Red, Color.LightGoldenrodYellow, 45.0f);
zedGraphControl1.AxisChange();
zedGraphControl1.Refresh();
}
}
}