Использование компонента MS Chart в C# и попытка определения элемента hit (HitResult). Кажется, что результат не всегда точным. Если у меня две диаграммы. Правая сторона - это диаграмма столбцов. Левая сторона иногда представляет собой диаграмму столбцов, а иногда и пончик. Элемент, возвращаемый с HitResult, когда левая сторона - это пончик, неверен. Изображение того, что я имею в виду:MSChart HitResult AxisLabel
namespace WindowsFormsApplication5
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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.DataPoint dataPoint1 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 10D);
System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint2 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 20D);
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint3 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 10D);
System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint4 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 20D);
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit();
this.SuspendLayout();
//
// chart1
//
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(13, 13);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Doughnut;
series1.Label = "bbb";
series1.Legend = "Legend1";
series1.Name = "Series1";
dataPoint1.AxisLabel = "AAA";
dataPoint2.AxisLabel = "BBB";
dataPoint2.Label = "aaa";
series1.Points.Add(dataPoint1);
series1.Points.Add(dataPoint2);
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(300, 300);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";
this.chart1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseDown);
//
// chart2
//
chartArea2.Name = "ChartArea1";
this.chart2.ChartAreas.Add(chartArea2);
legend2.Name = "Legend1";
this.chart2.Legends.Add(legend2);
this.chart2.Location = new System.Drawing.Point(341, 13);
this.chart2.Name = "chart2";
series2.ChartArea = "ChartArea1";
series2.Legend = "Legend1";
series2.Name = "Series1";
dataPoint3.AxisLabel = "111";
dataPoint4.AxisLabel = "2222";
series2.Points.Add(dataPoint3);
series2.Points.Add(dataPoint4);
this.chart2.Series.Add(series2);
this.chart2.Size = new System.Drawing.Size(300, 300);
this.chart2.TabIndex = 1;
this.chart2.Text = "chart2";
this.chart2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseDown);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(801, 490);
this.Controls.Add(this.chart2);
this.Controls.Add(this.chart1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
private System.Windows.Forms.DataVisualization.Charting.Chart chart2;
}
}
У вас есть два независимых графика, не так ли? По умолчанию каждый из них уже поставляется с ChartArea. Не нужно добавлять еще одну, если вы не хотите показывать две диаграммы в одном элементе управления Chart с двумя Chartareas. Кажется, вы смешиваете вещи. Не добавляйте второй ChartArea, если вы действительно не хотите два! Поскольку вы не показываете события __Two__ MosusClick & HitTest, мы можем только догадываться. Может быть, у вас есть только один? Но с двумя контрольными элементами диаграммы, которые не имеют смысла. Покажите нам больше кода, особенно __после того, как вы переключаете charttypes__! – TaW
Мне нужны две диаграммы, а не две диаграммы, поскольку диаграммы имеют разные ChartTypes. Я переключаю код - вручную, редактируя строку, которая определяет тип диаграммы для левой стороны и повторное выполнение. Полный код выше, и полный проект можно загрузить с [link] https://drive.google.com/open?id=0ByfxXBQPP7odOXdGVGFpdDB4Rk0) –
Вы можете легко иметь разные ChartTypes в двух ChartAreas того же элемента управления диаграммы. Даже в том же ChartArea, если типы совместимы. Пирог нет, но нет необходимости в 2-й диаграмме. Нет проблем, хотя .. - Вы действительно имели в виду, что вы меняете файл Designer.CS для изменения типов карт ??? Ой! Почему бы просто не сделать это в коде, может быть, нажатие кнопки ??? someSeries.ChartType = ... – TaW