msChart 问题 放大缩小问题+提示+空数据问题 紧急求助
各位同行好,
现在在用mschart画图,出了几个问题,一直解决不了,请求高人相助:
问题一:有关图的放大缩小问题,从一些帖子上看到需要设置CursorX属性如下,但是为啥在俺的项目里就愣是报错呢?
Chart1.ChartAreas["Default"].CursorX.IsUserEnabled = true;
Chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
Chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
错误提示:
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误消息: CS1061: “System.Web.UI.DataVisualization.Charting.ChartArea”不包含“CursorX”的定义,并且找不到可接受类型为“System.Web.UI.DataVisualization.Charting.ChartArea”的第一个参数的扩展方法“CursorX”(是否缺少 using 指令或程序集引用?)
PS:我的using集:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Threading;
using System.Linq;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Web.UI.DataVisualization;
using System.Web.UI.DataVisualization.Charting;
问题二:
我的绑定数据源的方法是这样的:
#region 创建曲线序列
String ChartType = DropDownList2.SelectedItem.Value.ToString();
System.Web.UI.DataVisualization.Charting.Series series;
for (int i = 1; i < MyDataSet.Tables[0].Columns.Count; i++)
{
series = Chart1.Series.Add(MyDataSet.Tables[0].Columns[i].ColumnName.ToString().Trim());
series.ChartArea = "Default";
series.ChartType = (System.Web.UI.DataVisualization.Charting.SeriesChartType)Enum.Parse(typeof(System.Web.UI.DataVisualization.Charting.SeriesChartType), ChartType);//曲线类型赋值
series.BorderWidth = 2;
series.BorderColor = System.Drawing.Color.Red;
series.MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle;
series.ShadowColor = Color.FromArgb(64, 0, 0, 0);
series.ShadowOffset = 2;
series.XValueType = ChartValueType.DateTime;
//绑定数据源,databind(行,横轴,纵轴)
//series.Points.DataBind(MyDataSet.Tables[0].Rows, MyDataSet.Tables[0].Columns[0].ToString(), MyDataSet.Tables[0].Columns[i].ToString(), "ToolTip=时间");
series.Points.DataBind(MyDataSet.Tables[0].Rows, MyDataSet.Tables[0].Columns[0].ToString(), MyDataSet.Tables[0].Columns[i].ToString(),"");
series.ToolTip = "时间:= #VALX{M}\n\n " + MyDataSet.Tables[0].Columns[i].ColumnName.ToString() + "= #VALY";
series.IsXValueIndexed = true;
series.IsXValueIndexed = true;
}
#endregion
想要的效果是:提示:时间=横轴时间 曲线XX的值为纵轴数值
但是用上面的方法 我的tooltip总是会出错 ,时间应该是横轴时间,但是提示的时间却是电脑的时间,悲剧鸟~~曲线没有提示错
高人帮忙
问题三:有些日期是没有数据的,这样的话,我想让曲线连起来,而不是断断续续的,我应该设置哪个属性呢?
问题四:看到坛子里都说有mschart的example,我咋没有啊 从哪里可以下载到呢,或者谁可以传给我一份啊,我的QQ邮箱:420372524@qq.com 不胜感激
任务紧急,求高人指点,不胜感激……
[最优解释]
http://archive.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=4418http://archive.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=4418
下载那个ASP.NET Samples
[其他解释]
//name program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace MSChart_Sample
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
//name Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
//for Visual Studio 2005 include this lines in "project_name.csproj"
/*
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Windows.Forms.DataVisualization">
<Name>System.Windows.Forms.DataVisualization</Name>
</Reference>
*/
namespace MSChart_Sample
{
class SimplerDialogBox : Form
{
private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
private System.Windows.Forms.Label labelSampleComment;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBoxChartType;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox comboBoxPointLabels;
private System.Windows.Forms.CheckBox checkBoxShowMargin;
private System.Windows.Forms.CheckBox checkBoxShow3D;
private System.Windows.Forms.Button buttonClose;
private System.Windows.Forms.Label label3;
public SimplerDialogBox()
{
Text = "Sample graph using MSChart";
FormBorderStyle = FormBorderStyle.FixedDialog;
ControlBox = false;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;
Button btn = new Button();
InitializeComponent();
this.chart1.Select();
}
private void LineCurvesChartType_Load(object sender, System.EventArgs e)
{
comboBoxChartType.SelectedIndex = 0;
comboBoxPointLabels.SelectedIndex = 0;
checkBoxShow3D.Checked = false;
// Populate series data
Random random = new Random();
for (int pointIndex = 0; pointIndex < 10; pointIndex++)
{
chart1.Series["Series1"].Points.AddY(random.Next(45, 95));
chart1.Series["Series2"].Points.AddY(random.Next(5, 65));
}
UpdateChartSettings();
}
private void UpdateChartSettings()
{
// Set series chart type
chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), comboBoxChartType.Text, true);
chart1.Series["Series2"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), comboBoxChartType.Text, true);
// Set point labels
if (comboBoxPointLabels.Text != "None")
{
chart1.Series["Series1"].IsValueShownAsLabel = true;
chart1.Series["Series2"].IsValueShownAsLabel = true;
if (comboBoxPointLabels.Text != "Auto")
{
chart1.Series["Series1"]["LabelStyle"] = comboBoxPointLabels.Text;
chart1.Series["Series2"]["LabelStyle"] = comboBoxPointLabels.Text;
}
}
else
{
chart1.Series["Series1"].IsValueShownAsLabel = false;
chart1.Series["Series2"].IsValueShownAsLabel = false;
}
// Set X axis margin
chart1.ChartAreas["Default"].AxisX.IsMarginVisible = checkBoxShowMargin.Checked;
}
private void comboBoxChartType_SelectedIndexChanged(object sender, System.EventArgs e)
{
UpdateChartSettings();
}
private void checkBoxShowMargin_CheckedChanged(object sender, System.EventArgs e)
{
UpdateChartSettings();
}
private void checkButtonClose(object sender, System.EventArgs e)
{
Close();
}
private void checkBoxShow3D_CheckedChanged(object sender, System.EventArgs e)
{
chart1.ChartAreas[0].Area3DStyle.Enable3D = checkBoxShow3D.Checked;
if (checkBoxShow3D.Checked)
{
chart1.Series["Series1"].MarkerStyle = MarkerStyle.None;
chart1.Series["Series2"].MarkerStyle = MarkerStyle.None;
chart1.Series["Series1"].BorderWidth = 1;
chart1.Series["Series2"].BorderWidth = 1;
}
else
{
chart1.Series["Series1"].MarkerStyle = MarkerStyle.Circle;
chart1.Series["Series2"].MarkerStyle = MarkerStyle.Diamond;
chart1.Series["Series1"].BorderWidth = 3;
chart1.Series["Series2"].BorderWidth = 3;
}
}
[其他解释]
接上
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.labelSampleComment = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.checkBoxShow3D = new System.Windows.Forms.CheckBox();
this.checkBoxShowMargin = new System.Windows.Forms.CheckBox();
this.comboBoxPointLabels = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.comboBoxChartType = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.buttonClose = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// chart1
//
this.chart1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(243)))), ((int)(((byte)(223)))), ((int)(((byte)(193)))));
this.chart1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
this.chart1.BorderlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(181)))), ((int)(((byte)(64)))), ((int)(((byte)(1)))));
this.chart1.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
this.chart1.BorderlineWidth = 2;
this.chart1.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;
chartArea1.Area3DStyle.Inclination = 40;
chartArea1.Area3DStyle.IsClustered = true;
chartArea1.Area3DStyle.IsRightAngleAxes = false;
chartArea1.Area3DStyle.LightStyle = System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
chartArea1.Area3DStyle.Perspective = 9;
chartArea1.Area3DStyle.Rotation = 25;
chartArea1.Area3DStyle.WallWidth = 3;
chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.BackColor = System.Drawing.Color.OldLace;
chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
chartArea1.BackSecondaryColor = System.Drawing.Color.White;
chartArea1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
chartArea1.Name = "Default";
chartArea1.ShadowColor = System.Drawing.Color.Transparent;
this.chart1.ChartAreas.Add(chartArea1);
legend1.BackColor = System.Drawing.Color.Transparent;
legend1.Enabled = false;
legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
legend1.IsTextAutoFit = false;
legend1.Name = "Default";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(16, 32);
this.chart1.Name = "chart1";
series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
series1.BorderWidth = 3;
series1.ChartArea = "Default";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
series1.Legend = "Default";
series1.MarkerSize = 8;
series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
series1.Name = "Series1";
series1.ShadowColor = System.Drawing.Color.Black;
series1.ShadowOffset = 2;
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
series2.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
series2.BorderWidth = 3;
series2.ChartArea = "Default";
series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(224)))), ((int)(((byte)(64)))), ((int)(((byte)(10)))));
series2.Legend = "Default";
series2.MarkerSize = 9;
series2.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Diamond;
series2.Name = "Series2";
series2.ShadowColor = System.Drawing.Color.Black;
series2.ShadowOffset = 2;
series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
series2.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
this.chart1.Series.Add(series1);
this.chart1.Series.Add(series2);
this.chart1.Size = new System.Drawing.Size(412, 296);
this.chart1.TabIndex = 1;
//
// labelSampleComment
//
this.labelSampleComment.Font = new System.Drawing.Font("Verdana", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelSampleComment.Location = new System.Drawing.Point(16, 0);
this.labelSampleComment.Name = "labelSampleComment";
this.labelSampleComment.Size = new System.Drawing.Size(702, 24);
this.labelSampleComment.TabIndex = 0;
this.labelSampleComment.Text = "This sample demonstrates the Line, Spline and, StepLine chart types. ";
this.labelSampleComment.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// panel1
//
this.panel1.Controls.Add(this.buttonClose);
this.panel1.Controls.Add(this.checkBoxShow3D);
this.panel1.Controls.Add(this.checkBoxShowMargin);
this.panel1.Controls.Add(this.comboBoxPointLabels);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.comboBoxChartType);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(432, 40);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(292, 280);
this.panel1.TabIndex = 2;
//
// checkBoxShow3D
[其他解释]
接上//
this.checkBoxShow3D.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.checkBoxShow3D.Location = new System.Drawing.Point(14, 104);
this.checkBoxShow3D.Name = "checkBoxShow3D";
this.checkBoxShow3D.Size = new System.Drawing.Size(168, 24);
this.checkBoxShow3D.TabIndex = 5;
this.checkBoxShow3D.Text = "Display chart as 3&D:";
this.checkBoxShow3D.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.checkBoxShow3D.CheckedChanged += new System.EventHandler(this.checkBoxShow3D_CheckedChanged);
//
// checkBoxShowMargin
//
this.checkBoxShowMargin.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.checkBoxShowMargin.Location = new System.Drawing.Point(14, 72);
this.checkBoxShowMargin.Name = "checkBoxShowMargin";
this.checkBoxShowMargin.Size = new System.Drawing.Size(168, 24);
this.checkBoxShowMargin.TabIndex = 4;
this.checkBoxShowMargin.Text = "Show X Axis &Margin:";
this.checkBoxShowMargin.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.checkBoxShowMargin.CheckedChanged += new System.EventHandler(this.checkBoxShowMargin_CheckedChanged);
//
// close
//
this.buttonClose.Location = new System.Drawing.Point(180, 180);
this.buttonClose.Name = "buttonClose";
this.buttonClose.Size = new System.Drawing.Size(60, 30);
this.buttonClose.TabIndex = 6;
this.buttonClose.Text = "Close";
this.buttonClose.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.buttonClose.Click += new System.EventHandler(this.checkButtonClose);
//
// comboBoxPointLabels
//
this.comboBoxPointLabels.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxPointLabels.Items.AddRange(new object[] {
"None",
"Auto",
"TopLeft",
"Top",
"TopRight",
"Right",
"BottomRight",
"Bottom",
"BottomLeft",
"Left",
"Center"});
this.comboBoxPointLabels.Location = new System.Drawing.Point(168, 40);
this.comboBoxPointLabels.Name = "comboBoxPointLabels";
this.comboBoxPointLabels.Size = new System.Drawing.Size(104, 22);
this.comboBoxPointLabels.TabIndex = 3;
this.comboBoxPointLabels.SelectedIndexChanged += new System.EventHandler(this.comboBoxChartType_SelectedIndexChanged);
//
// label2
//
this.label2.Location = new System.Drawing.Point(3, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(160, 23);
this.label2.TabIndex = 2;
this.label2.Text = "Point &Labels:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// comboBoxChartType
//
this.comboBoxChartType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxChartType.Items.AddRange(new object[] {
"Line",
"Spline",
"StepLine"});
this.comboBoxChartType.Location = new System.Drawing.Point(168, 8);
this.comboBoxChartType.Name = "comboBoxChartType";
this.comboBoxChartType.Size = new System.Drawing.Size(104, 22);
this.comboBoxChartType.TabIndex = 1;
this.comboBoxChartType.SelectedIndexChanged += new System.EventHandler(this.comboBoxChartType_SelectedIndexChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(3, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(160, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Chart &Type:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Font = new System.Drawing.Font("Verdana", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(13, 336);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(702, 40);
this.label3.TabIndex = 4;
this.label3.Text = "The label style can be set using the LabelStyle custom attribute, and the ShowMar" +
"kers custom attribute is used to display data point markers when the chart area " +
"is set to 3D.";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// LineCurvesChartType
//
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.label3);
this.Controls.Add(this.panel1);
this.Controls.Add(this.labelSampleComment);
this.Controls.Add(this.chart1);
this.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "LineCurvesChartType";
this.Size = new System.Drawing.Size(728, 384);
this.Load += new System.EventHandler(this.LineCurvesChartType_Load);
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FirstMainMenu();
}
public void FirstMainMenu()
{
MenuItem miGraph = new MenuItem("&Graph", new EventHandler(MenuSampleGraphOnClick));
MenuItem miExit = new MenuItem("E&xit", new EventHandler(MenuFileExitOnClick));
MenuItem miSample = new MenuItem("&Sample", new MenuItem[] { miGraph, miExit });
//--------------------
MenuItem miAbout = new MenuItem("&About " + Text, new EventHandler(MenuHelpAboutOnClick));
MenuItem miHelp = new MenuItem("&Help", new MenuItem[] { miAbout });
//-------------------------
Menu = new MainMenu(new MenuItem[] { miSample, miHelp });
//-------------------------
}
void MenuHelpAboutOnClick(object obj, EventArgs ea)
{
MessageBox.Show(Text + " - Sample graph using MSChart API");
}
void MenuFileExitOnClick(object obj, EventArgs ea)
{
Close();
}
//-----------------------------------------------------
void MenuSampleGraphOnClick(object obj, EventArgs ea)
{
SimplerDialogBox dlg = new SimplerDialogBox();
DialogResult dr = dlg.ShowDialog();
Console.WriteLine(dr);
}
}
}
[其他解释]
楼上的大哥,首先 非常感谢您的出手相助,然后我想问下,原理是什么呢?我的是在asp里面拖了个mschart控件进去。。。上面那些namespace 写到哪里去呢?
[其他解释]
我需要web下的应用。在asp.net中运用
[其他解释]
http://archive.msdn.microsoft.com/mschart
下载这个吧
[其他解释]
您好,我现在也遇到了这个问题,请问你是这么解决的呢?