预览
代码
手机端效果
web端效果
demoBarChart.cs
demoBarChart.Designer.cs
web:demoBarChart.cs
web:demoBarChart.Designer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using System.Data;
namespace Smobiler.Tutorials.Components
{
partial class demoBarChart : Smobiler.Core.Controls.MobileForm
{
public demoBarChart()
: base()
{
//This call is required by the SmobilerForm.
InitializeComponent();
}
DataTable dt = null;
private void title1_ImagePress(object sender, EventArgs e)
{
this.Close();
}
private void button1_Press(object sender, EventArgs e)
{
this.popList1.ShowDialog();
}
private void demoBarChart_Load(object sender, EventArgs e)
{
PopListGroup g1 = new PopListGroup();
g1.AddListItem("DataBind");
g1.AddListItem("AddSet");
g1.AddListItem("RemoveSet");
g1.AddListItem("ClearSet");
g1.AddListItem("SetData");
popList1.Groups.Add(g1);
}
private void popList1_Selected(object sender, EventArgs e)
{
switch (popList1.Selections[0].Text)
{
case "DataBind":
DataBind();
break;
case "AddSet":
this.barChart1.Data.AddSeries(GetNewSerie(this.barChart1.Data));
break;
case "RemoveSet":
if (this.barChart1.Data.SeriesCount > 0)
{
this.barChart1.Data.RemoveSeries(0);
}
break;
case "ClearSet":
this.barChart1.Data.ClearValues();
break;
case "SetData":
List xLabels = new List();
xLabels.AddRange(new string[] { "1", "2", "3", "4" });
BarData data = new BarData(xLabels);
data.AddSeries(GetNewSerie(data));
this.barChart1.Data = data;
break;
}
}
private void DataBind()
{
//设置数据
this.barChart1.SeriesMember = "S";
this.barChart1.XValueMember = "X";
this.barChart1.YValueMember = "Y";
this.barChart1.XAxis.AxisLineColor = DemoGlobal.GetRandomColor();
this.barChart1.XAxis.GridColor = DemoGlobal.GetRandomColor();
dt = DemoGlobal.GetChartDemoTable();
this.barChart1.DataSource = dt;
this.barChart1.DataBind();
}
private BarSeries GetNewSerie(BarData data)
{
Random countRandom = new Random();
ChartYAxisValueCollection yVals = new ChartYAxisValueCollection();
int count = data.XAxisCount;
for (int i = 0; i < count; i++)
{
yVals.Add(new BarYAxisValue(countRandom.Next(0, count)));
}
BarSeries set1 = new BarSeries(yVals, "DataSet 1");
set1.AddColor(DemoGlobal.GetRandomColor());
set1.AddColor(DemoGlobal.GetRandomColor());
set1.AddColor(DemoGlobal.GetRandomColor());
return set1;
}
private void barChart1_ValueSelected(object sender, BarChartValueSelectedEventArgs e)
{
Toast(string.Format("X:{0}/Y:{1}", e.XValue, e.YValue.Val));
}
}
}
using System;
using Smobiler.Core;
namespace Smobiler.Tutorials.Components
{
partial class demoBarChart : Smobiler.Core.Controls.MobileForm
{
#region "SmobilerForm generated code "
//SmobilerForm overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerForm
//It can be modified using the SmobilerForm.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.title1 = new Smobiler.Core.Controls.Title();
this.panel10 = new Smobiler.Core.Controls.Panel();
this.panel1 = new Smobiler.Core.Controls.Panel();
this.labContent = new Smobiler.Core.Controls.Label();
this.labTitle = new Smobiler.Core.Controls.Label();
this.button1 = new Smobiler.Core.Controls.Button();
this.barChart1 = new Smobiler.Core.Controls.BarChart();
this.popList1 = new Smobiler.Core.Controls.PopList();
//
// title1
//
this.title1.ImageType = Smobiler.Core.Controls.ImageEx.ImageStyle.FontIcon;
this.title1.Name = "title1";
this.title1.ResourceID = "angle-left";
this.title1.Size = new System.Drawing.Size(300, 30);
this.title1.Text = "BarChart";
this.title1.ImagePress += new System.EventHandler(this.title1_ImagePress);
//
// panel10
//
this.panel10.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.panel1,
this.barChart1});
this.panel10.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel10.Location = new System.Drawing.Point(0, 30);
this.panel10.Name = "panel10";
this.panel10.Scrollable = true;
this.panel10.Size = new System.Drawing.Size(300, 970);
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Border = new Smobiler.Core.Controls.Border(1F);
this.panel1.BorderColor = System.Drawing.Color.Silver;
this.panel1.BorderRadius = 5;
this.panel1.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.labContent,
this.labTitle,
this.button1});
this.panel1.Location = new System.Drawing.Point(5, 9);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(290, 123);
//
// labContent
//
this.labContent.BackColor = System.Drawing.Color.WhiteSmoke;
this.labContent.FontSize = 15F;
this.labContent.Location = new System.Drawing.Point(0, 26);
this.labContent.Name = "labContent";
this.labContent.Padding = new Smobiler.Core.Controls.Padding(5F);
this.labContent.Size = new System.Drawing.Size(290, 54);
this.labContent.Text = "可进行数据绑定,添加数据集,删除数据集,清除数据集,设置数据集的操作\r\n";
//
// labTitle
//
this.labTitle.BackColor = System.Drawing.Color.WhiteSmoke;
this.labTitle.Border = new Smobiler.Core.Controls.Border(0F, 0F, 0F, 1F);
this.labTitle.BorderColor = System.Drawing.Color.DarkSeaGreen;
this.labTitle.FontSize = 16F;
this.labTitle.Name = "labTitle";
this.labTitle.Padding = new Smobiler.Core.Controls.Padding(5F);
this.labTitle.Size = new System.Drawing.Size(290, 26);
this.labTitle.Text = "柱状图表";
//
// button1
//
this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(67)))), ((int)(((byte)(81)))));
this.button1.Location = new System.Drawing.Point(39, 87);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(212, 30);
this.button1.Text = "控件介绍";
this.button1.Press += new System.EventHandler(this.button1_Press);
//
// barChart1
//
this.barChart1.Location = new System.Drawing.Point(0, 138);
this.barChart1.Name = "barChart1";
this.barChart1.Size = new System.Drawing.Size(300, 300);
this.barChart1.XAxisValues = new string[0];
this.barChart1.ValueSelected += new Smobiler.Core.Controls.BarChartValueSelectedEventHandler(this.barChart1_ValueSelected);
//
// popList1
//
this.popList1.Name = "popList1";
this.popList1.Selected += new System.EventHandler(this.popList1_Selected);
//
// demoBarChart
//
this.Components.AddRange(new Smobiler.Core.Controls.MobileComponent[] {
this.popList1});
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.title1,
this.panel10});
this.Load += new System.EventHandler(this.demoBarChart_Load);
this.Name = "demoBarChart";
}
#endregion
private Core.Controls.Title title1;
private Core.Controls.Panel panel10;
private Core.Controls.Panel panel1;
private Core.Controls.Label labContent;
private Core.Controls.Label labTitle;
private Core.Controls.BarChart barChart1;
private Core.Controls.Button button1;
private Core.Controls.PopList popList1;
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using Smobiler.Tutorials.Components;
namespace SmobilerTutorialsWeb
{
partial class demoBarChart : Smobiler.Core.Controls.MobileForm
{
public demoBarChart() : base()
{
//This call is required by the SmobilerForm.
InitializeComponent();
}
DataTable dt = null;
private void demoBarChart_Load(object sender, EventArgs e)
{
spinner1.Items = new string[] { "DataBind", "AddSet" , "RemoveSet","ClearSet", "SetData" };
}
private void title1_ImagePress(object sender, EventArgs e)
{
this.Close();
}
private void barChart1_ValueSelected(object sender, BarChartValueSelectedEventArgs e)
{
Toast(string.Format("X:{0}/Y:{1}", e.XValue, e.YValue.Val));
}
private void spinner1_ItemSelected(object sender, SpinnerItemSelectedEventArgs e)
{
switch (spinner1.Text)
{
case "DataBind":
DataBind();
break;
case "AddSet":
this.barChart1.Data.AddSeries(GetNewSerie(this.barChart1.Data));
break;
case "RemoveSet":
if (this.barChart1.Data.SeriesCount > 0)
{
this.barChart1.Data.RemoveSeries(0);
}
break;
case "ClearSet":
this.barChart1.Data.ClearValues();
break;
case "SetData":
List xLabels = new List();
xLabels.AddRange(new string[] { "1", "2", "3", "4" });
BarData data = new BarData(xLabels);
data.AddSeries(GetNewSerie(data));
this.barChart1.Data = data;
break;
}
}
private void DataBind()
{
//设置数据
this.barChart1.SeriesMember = "S";
this.barChart1.XValueMember = "X";
this.barChart1.YValueMember = "Y";
this.barChart1.XAxis.AxisLineColor = DemoGlobal.GetRandomColor();
this.barChart1.XAxis.GridColor = DemoGlobal.GetRandomColor();
dt = DemoGlobal.GetChartDemoTable();
this.barChart1.DataSource = dt;
this.barChart1.DataBind();
}
private BarSeries GetNewSerie(BarData data)
{
Random countRandom = new Random();
ChartYAxisValueCollection yVals = new ChartYAxisValueCollection();
int count = data.XAxisCount;
for (int i = 0; i < count; i++)
{
yVals.Add(new BarYAxisValue(countRandom.Next(0, count)));
}
BarSeries set1 = new BarSeries(yVals, "DataSet 1");
set1.AddColor(DemoGlobal.GetRandomColor());
set1.AddColor(DemoGlobal.GetRandomColor());
set1.AddColor(DemoGlobal.GetRandomColor());
return set1;
}
}
}
using System;
using Smobiler.Core;
namespace SmobilerTutorialsWeb
{
partial class demoBarChart : Smobiler.Core.Controls.MobileForm
{
#region "SmobilerForm generated code "
//SmobilerForm overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerForm
//It can be modified using the SmobilerForm.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.title1 = new Smobiler.Core.Controls.Title();
this.panel10 = new Smobiler.Core.Controls.Panel();
this.panel1 = new Smobiler.Core.Controls.Panel();
this.labContent = new Smobiler.Core.Controls.Label();
this.labTitle = new Smobiler.Core.Controls.Label();
this.barChart1 = new Smobiler.Core.Controls.BarChart();
this.spinner1 = new Smobiler.Core.Controls.Spinner();
//
// title1
//
this.title1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(246)))), ((int)(((byte)(246)))), ((int)(((byte)(246)))));
this.title1.ImageType = Smobiler.Core.Controls.ImageEx.ImageStyle.FontIcon;
this.title1.Name = "title1";
this.title1.ResourceID = "angle-left";
this.title1.Size = new System.Drawing.Size(0, 30);
this.title1.Text = "BarChart";
this.title1.ImagePress += new System.EventHandler(this.title1_ImagePress);
//
// panel10
//
this.panel10.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.panel1,
this.labTitle});
this.panel10.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel10.Flex = 1;
this.panel10.Name = "panel10";
this.panel10.Scrollable = true;
this.panel10.Size = new System.Drawing.Size(0, 0);
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Border = new Smobiler.Core.Controls.Border(1F);
this.panel1.BorderColor = System.Drawing.Color.Silver;
this.panel1.BorderRadius = 5;
this.panel1.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.labContent,
this.barChart1,
this.spinner1});
this.panel1.Location = new System.Drawing.Point(301, 57);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(600, 527);
//
// labContent
//
this.labContent.BackColor = System.Drawing.Color.White;
this.labContent.HorizontalAlignment = Smobiler.Core.Controls.HorizontalAlignment.Center;
this.labContent.Location = new System.Drawing.Point(0, 109);
this.labContent.Name = "labContent";
this.labContent.Padding = new Smobiler.Core.Controls.Padding(5F);
this.labContent.Size = new System.Drawing.Size(599, 32);
this.labContent.Text = "可进行数据绑定,添加数据集,删除数据集,清除数据集,设置数据集的操作\r\n";
//
// labTitle
//
this.labTitle.BackColor = System.Drawing.Color.White;
this.labTitle.Bold = true;
this.labTitle.Border = new Smobiler.Core.Controls.Border(0F, 0F, 0F, 1F);
this.labTitle.BorderColor = System.Drawing.Color.White;
this.labTitle.FontSize = 16F;
this.labTitle.Location = new System.Drawing.Point(301, 30);
this.labTitle.Name = "labTitle";
this.labTitle.Size = new System.Drawing.Size(600, 26);
this.labTitle.Text = "柱状图表";
//
// barChart1
//
this.barChart1.Location = new System.Drawing.Point(150, 175);
this.barChart1.Name = "barChart1";
this.barChart1.Size = new System.Drawing.Size(300, 300);
this.barChart1.XAxisValues = new string[0];
this.barChart1.ValueSelected += new Smobiler.Core.Controls.BarChartValueSelectedEventHandler(this.barChart1_ValueSelected);
//
// spinner1
//
this.spinner1.Location = new System.Drawing.Point(150, 45);
this.spinner1.Name = "spinner1";
this.spinner1.Size = new System.Drawing.Size(300, 30);
this.spinner1.ItemSelected += new System.EventHandler(this.spinner1_ItemSelected);
//
// demoBarChart
//
this.BackColor = System.Drawing.Color.White;
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.title1,
this.panel10});
this.Layout = Smobiler.Core.Controls.LayoutPosition.Relative;
this.Size = new System.Drawing.Size(1200, 800);
this.Load += new System.EventHandler(this.demoBarChart_Load);
this.Name = "demoBarChart";
}
#endregion
private Smobiler.Core.Controls.Title title1;
private Smobiler.Core.Controls.Panel panel10;
private Smobiler.Core.Controls.Panel panel1;
private Smobiler.Core.Controls.Label labContent;
private Smobiler.Core.Controls.BarChart barChart1;
private Smobiler.Core.Controls.Spinner spinner1;
private Smobiler.Core.Controls.Label labTitle;
}
}