380 lines
16 KiB
C#
380 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using CommonLib;
|
|
using System.Data.SqlClient;
|
|
using DevExpress.XtraCharts;
|
|
using DevExpress.Utils;
|
|
|
|
namespace Lskj.MyControl.Panel_Chart
|
|
{
|
|
public partial class Panel_Chart : UserControl
|
|
{
|
|
public string DLLCoid { get; set; }
|
|
public string formKey { get; set; }
|
|
public string FormText { get; set; }
|
|
public string OperatorId { get; set; }
|
|
public string OperatorName { get; set; }
|
|
public string Privilege { get; set; }
|
|
public ChartControl chartControl { get { return chartMain; } }
|
|
public SeriesPoint seriesPoint { get; set; }
|
|
|
|
private Color[] colorList = { Color.Red, Color.Orange, Color.Black, Color.Blue, Color.BlueViolet, Color.BlanchedAlmond };
|
|
//private string Formkey;
|
|
//private string CondKey;
|
|
|
|
private DataTable dtTypeChart;
|
|
private DataTable dtData;
|
|
public string ConstSQL = string.Empty;
|
|
private ToolTipController toolTipController = new ToolTipController();
|
|
public string SQL
|
|
{
|
|
get { return reportSql; }
|
|
set {
|
|
String chartSql = String.Format("select * from p_systemdlltabchart where tabkey='{0}' and isVisible=0", formKey);
|
|
if (dtTypeChart == null)
|
|
{
|
|
dtTypeChart = SqlHelper.ExecuteDataSet(chartSql).Tables[0];
|
|
}
|
|
reportSql = value;
|
|
|
|
dtData = SqlHelper.ExecuteDataSet(reportSql).Tables[0];
|
|
CreateChart();
|
|
}
|
|
}
|
|
|
|
public int AutoQuery { get; set; }
|
|
public string[] Params { get; set; }
|
|
private string reportSql = string.Empty;
|
|
|
|
public Panel_Chart()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
//String SQL = String.Format("select * from p_systemdlltab where dllcoid='{0}'", DLLCoid);
|
|
//DataTable dtSystemdlltab = SqlHelper.ExecuteDataSet(SQL).Tables[0];
|
|
//if (dtSystemdlltab != null && dtSystemdlltab.Rows.Count > 0)
|
|
//{
|
|
// reportSql = dtSystemdlltab.Rows[0]["SQL"] + "";
|
|
// if (dtSystemdlltab.Rows.Count > 0)
|
|
// {
|
|
// Formkey = dtSystemdlltab.Rows[0]["formKey"] + "";
|
|
// CondKey = dtSystemdlltab.Rows[0]["CondKey"] + "";
|
|
// }
|
|
// SqlParameter[] p =
|
|
// {
|
|
// new SqlParameter("@modid",SqlDbType.VarChar,50),
|
|
// new SqlParameter("@operatorname",SqlDbType.VarChar,50)
|
|
// };
|
|
// p[0].Value = DLLCoid;
|
|
// p[1].Value = OperatorName;
|
|
//DataTable dtFileds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_getBaseModuleField", "temp", p).Tables[0];
|
|
//PubControl.SetColumns(gcMain, dtFileds);
|
|
//String chartSql = String.Format("select * from p_systemdlltabchart where tabkey='{0}' and isVisible=0", formKey);
|
|
//dtTypeChart = SqlHelper.ExecuteDataSet(chartSql).Tables[0];
|
|
//reportSql = SQL;
|
|
//dtData = SqlHelper.ExecuteDataSet(reportSql).Tables[0];
|
|
//CreateChart();
|
|
//添加右键菜单
|
|
//DataRow dtSystemwordbooktaNo = SqlHelper.ExecuteDataSet("select top 1 * from P_systemwordbooktab where tab='" + DLLCoid + "' order by orderid").Tables[0].Rows[0];
|
|
//GridMenu gm = new GridMenu(FormText, OperatorId, OperatorName, Privilege, DLLCoid, "", gcMain);
|
|
//gm.DirId = dtSystemdlltab.Rows[0]["dirid"] + "";
|
|
//gm.filedKey = dtSystemwordbooktaNo["fieldname"].ToString();
|
|
//gm.BindGridMenuWQ(DLLCoid);
|
|
//}
|
|
//gcMain.DataSource = dtData;
|
|
//SearchCraeteControl();
|
|
chartMain.RuntimeHitTesting = true;
|
|
|
|
}
|
|
|
|
private void CreateChart()
|
|
{
|
|
if (chartMain.Diagram is XYDiagram)
|
|
((XYDiagram)chartMain.Diagram).SecondaryAxesY.Clear();
|
|
chartMain.Series.Clear();
|
|
for (int i = 0; i < dtTypeChart.Rows.Count; i++)
|
|
{
|
|
DataRow row = dtTypeChart.Rows[i];
|
|
int chartType = Convert.ToInt32(row["chartType"]);
|
|
int YAxisShared = Convert.ToInt32(row["YAxisShared"]);
|
|
String YAxisTitle = row["YAxisTitle"] + "";
|
|
int chart3D = Convert.ToInt32(row["chart3D"]);
|
|
|
|
Series series = null;
|
|
if (chartType == ChartType.line)
|
|
{
|
|
if (chart3D == 1)
|
|
{
|
|
series = new Series(YAxisTitle, ViewType.Line3D);
|
|
}
|
|
else
|
|
{
|
|
series = new Series(YAxisTitle, ViewType.Line);
|
|
}
|
|
}
|
|
else if (chartType == ChartType.bar)
|
|
{
|
|
if (chart3D == 1)
|
|
{
|
|
series = new Series(YAxisTitle, ViewType.Bar3D);
|
|
}
|
|
else
|
|
{
|
|
series = new Series(YAxisTitle, ViewType.Bar);
|
|
}
|
|
}
|
|
else if (chartType == ChartType.pie)
|
|
{
|
|
if (chart3D == 1)
|
|
{
|
|
series = new Series(YAxisTitle, ViewType.Doughnut3D);
|
|
((PiePointOptions)series.LegendPointOptions).PointView = PointView.ArgumentAndValues;
|
|
Doughnut3DSeriesView view = series.View as Doughnut3DSeriesView;
|
|
view.ExplodeMode = PieExplodeMode.All;
|
|
series.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
|
|
series.LabelsVisibility = DefaultBoolean.True;
|
|
PiePointOptions options = series.Label.PointOptions as PiePointOptions;
|
|
if (options != null)
|
|
{
|
|
options.PercentOptions.ValueAsPercent = true;
|
|
options.PointView = PointView.ArgumentAndValues;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
series = new Series(YAxisTitle, ViewType.Pie);
|
|
PiePointOptions options = series.Label.PointOptions as PiePointOptions;
|
|
series.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
|
|
((PiePointOptions)series.LegendPointOptions).PointView = PointView.ArgumentAndValues;
|
|
PieSeriesView view = series.View as PieSeriesView;
|
|
view.ExplodeMode = PieExplodeMode.All;
|
|
view.Rotation = 50;
|
|
view.RuntimeExploding = true;
|
|
series.LabelsVisibility = DefaultBoolean.True;
|
|
if (options != null)
|
|
{
|
|
options.PercentOptions.ValueAsPercent = true;
|
|
options.PointView = PointView.ArgumentAndValues;
|
|
}
|
|
}
|
|
}
|
|
if (series != null)
|
|
{
|
|
series.View.Color = System.Drawing.ColorTranslator.FromHtml(row["chartColor"] + "");
|
|
}
|
|
foreach (DataRow dr in dtData.Rows)
|
|
{
|
|
String XLabelField = row["XLabelField"] + "";
|
|
String YValueField = row["YValueField"] + "";
|
|
if (chartType == ChartType.pie)
|
|
{
|
|
if (chart3D == 1)
|
|
{
|
|
CreateSeriesPie3D(dr[XLabelField] + "", dr[YValueField] + "", series);
|
|
}
|
|
else
|
|
{
|
|
CreateSeriesPie(dr[XLabelField] + "", dr[YValueField] + "", series);
|
|
}
|
|
}
|
|
else if (chartType == ChartType.bar)
|
|
{
|
|
if (chart3D == 1)
|
|
{
|
|
CreateSeriesBar3D(dr[XLabelField] + "", dr[YValueField] + "", series);
|
|
}
|
|
else
|
|
{
|
|
CreateSeries(dr[XLabelField] + "", dr[YValueField] + "", series);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CreateSeries(dr[XLabelField] + "", dr[YValueField] + "", series);
|
|
}
|
|
}
|
|
|
|
chartMain.Series.Add(series);
|
|
|
|
if ((YAxisShared == 0)&&(series!=null))
|
|
{
|
|
CreateAxisY(series, chartType, chart3D);
|
|
}
|
|
}
|
|
chartMain.Legend.Visible = true;
|
|
chartMain.SeriesTemplate.LabelsVisibility = DefaultBoolean.True;
|
|
chartMain.CrosshairEnabled = DefaultBoolean.True;
|
|
chartMain.ToolTipEnabled = DefaultBoolean.True;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据数据创建一个图形展现
|
|
/// </summary>
|
|
/// <param name="caption">图形标题</param>
|
|
/// <param name="viewType">图形类型</param>
|
|
/// <param name="dt">数据DataTable</param>
|
|
/// <param name="rowIndex">图形数据的行序号</param>
|
|
/// <returns></returns>
|
|
private Series CreateSeriesBar3D(String colName, String colValue, Series series)
|
|
{
|
|
series.Points.Add(new SeriesPoint(colName + "" == "" ? "*指标为空*" : colName, new double[] { Convert.ToDouble(colValue + "" == "" ? "0" : colValue) }));
|
|
return series;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 根据数据创建一个图形展现
|
|
/// </summary>
|
|
/// <param name="caption">图形标题</param>
|
|
/// <param name="viewType">图形类型</param>
|
|
/// <param name="dt">数据DataTable</param>
|
|
/// <param name="rowIndex">图形数据的行序号</param>
|
|
/// <returns></returns>
|
|
private Series CreateSeriesPie3D(String colName, String colValue, Series series)
|
|
{
|
|
series.Points.Add(new SeriesPoint(colName + "" == "" ? "*指标为空*" : colName, new double[] { Convert.ToDouble(colValue + "" == "" ? "0" : colValue) }));
|
|
return series;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据数据创建一个图形展现
|
|
/// </summary>
|
|
/// <param name="caption">图形标题</param>
|
|
/// <param name="viewType">图形类型</param>
|
|
/// <param name="dt">数据DataTable</param>
|
|
/// <param name="rowIndex">图形数据的行序号</param>
|
|
/// <returns></returns>
|
|
private Series CreateSeriesPie(String colName, String colValue, Series series)
|
|
{
|
|
series.Points.Add(new SeriesPoint(colName + "" == "" ? "*指标为空*" : colName, new double[] { Convert.ToDouble(colValue + "" == "" ? "0" : colValue) }));
|
|
return series;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据数据创建一个图形展现
|
|
/// </summary>
|
|
/// <param name="caption">图形标题</param>
|
|
/// <param name="viewType">图形类型</param>
|
|
/// <param name="dt">数据DataTable</param>
|
|
/// <param name="rowIndex">图形数据的行序号</param>
|
|
/// <returns></returns>
|
|
private Series CreateSeries(String colName, String colValue, Series series)
|
|
{
|
|
series.Points.Add(new SeriesPoint(colName + "" == "" ? "*指标为空*" : colName, colValue+"" == "" ? "0" : colValue));
|
|
series.ArgumentScaleType = ScaleType.Qualitative;
|
|
series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//显示标注标签
|
|
return series;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建图表的第二坐标系
|
|
/// </summary>
|
|
/// <param name="series">Series对象</param>
|
|
/// <returns></returns>
|
|
private SecondaryAxisY CreateAxisY(Series series, int chartType, int chart3D)
|
|
{
|
|
|
|
SecondaryAxisY myAxis = new SecondaryAxisY(series.Name);
|
|
((XYDiagram)chartMain.Diagram).SecondaryAxesY.Add(myAxis);
|
|
if (chartType == ChartType.line)
|
|
((LineSeriesView)series.View).AxisY = myAxis;
|
|
if (chartType == ChartType.bar)
|
|
((BarSeriesView)series.View).AxisY = myAxis;
|
|
|
|
myAxis.Title.Text = series.Name;
|
|
myAxis.Title.Alignment = StringAlignment.Far; //顶部对齐
|
|
myAxis.Title.Visible = true; //显示标题
|
|
myAxis.Title.Font = new Font("宋体", 9.0f);
|
|
Color color = series.View.Color;//设置坐标的颜色和图表线条颜色一致
|
|
myAxis.Title.TextColor = color;
|
|
myAxis.Label.TextColor = color;
|
|
myAxis.Color = color;
|
|
return myAxis;
|
|
}
|
|
|
|
private void chartMain_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void chartMain_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
seriesPoint = null;
|
|
ChartHitInfo hitInfo = chartMain.CalcHitInfo(e.Location);
|
|
StringBuilder builder = new StringBuilder();
|
|
if (hitInfo.InDiagram)
|
|
builder.AppendLine("In Diagram");
|
|
if (hitInfo.InNonDefaultPane)
|
|
builder.AppendLine("In non-default pane: " + hitInfo.NonDefaultPane.Name);
|
|
if (hitInfo.InAxis)
|
|
{
|
|
builder.AppendLine("In axis: " + hitInfo.Axis.Name);
|
|
if (hitInfo.AxisLabelItem != null)
|
|
builder.AppendLine(" Label item: " + hitInfo.AxisLabelItem.Text);
|
|
if (hitInfo.AxisTitle != null)
|
|
builder.AppendLine(" Axis title: " + hitInfo.AxisTitle.Text);
|
|
}
|
|
if (hitInfo.InChartTitle)
|
|
builder.AppendLine("In chart title: " + hitInfo.ChartTitle.Text);
|
|
if (hitInfo.InLegend)
|
|
builder.AppendLine("In legend");
|
|
if (hitInfo.InSeries)
|
|
builder.AppendLine("In series: " + ((Series)hitInfo.Series).Name);
|
|
if (hitInfo.InSeriesLabel)
|
|
{
|
|
builder.AppendLine("In series label");
|
|
builder.AppendLine(" Series: " + ((Series)hitInfo.Series).Name);
|
|
}
|
|
if (hitInfo.SeriesPoint != null)
|
|
{
|
|
seriesPoint = hitInfo.SeriesPoint;
|
|
builder.AppendLine(" Argument: " + hitInfo.SeriesPoint.Argument);
|
|
if (!hitInfo.SeriesPoint.IsEmpty)
|
|
builder.AppendLine(" Value: " + hitInfo.SeriesPoint.Values[0]);
|
|
}
|
|
//if (builder.Length > 0)
|
|
// toolTipController.ShowHint("Hit-testing results:\n" + builder.ToString(), chartMain.PointToScreen(e.Location));
|
|
//else
|
|
// toolTipController.HideHint();
|
|
}
|
|
|
|
private void chartMain_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
ChartHitInfo hitInfo = chartMain.CalcHitInfo(e.Location);
|
|
if (hitInfo.SeriesPoint != null)
|
|
{
|
|
if (chartMain.ContextMenuStrip != null)
|
|
{
|
|
foreach (ToolStripMenuItem item in chartMain.ContextMenuStrip.Items)
|
|
{
|
|
if (item.Tag == null)
|
|
continue;
|
|
DataRow dr = item.Tag as DataRow;
|
|
if (dr == null)
|
|
continue;
|
|
|
|
if (dr.Table.Columns.Contains("DBClickEvent"))
|
|
{
|
|
if (dr["DBClickEvent"] + "" == "1")
|
|
{
|
|
item.PerformClick();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|