Exemplo n.º 1
0
        private void c1Chart1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            string newLabText = e.Data.GetData(DataFormats.Text).ToString();

            if (newLabText != null && newLabText.Length > 0)
            {
                // convert the event screen coords to client coords
                // of the chart object.
                Point      pnt = c1Chart1.PointToClient(new Point(e.X, e.Y));
                ChartGroup grp = c1Chart1.ChartGroups[0];
                int        s = -1, p = -1, d = -1;

                // the cursor MUST be on a bar.
                if (grp.CoordToDataIndex(pnt.X, pnt.Y, CoordinateFocusEnum.XandYCoord, ref s, ref p, ref d))
                {
                    if (s >= 0 && p >= 0 && d == 0)
                    {
                        // create the label name
                        string labName = "barLabel_" + s.ToString() + "_" + p.ToString();

                        // now get the existing label or create it if necessary
                        C1.Win.C1Chart.Label lab = c1Chart1.ChartLabels[labName];
                        if (lab == null)
                        {
                            // create the label
                            lab              = c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
                            lab.Name         = labName;
                            lab.Compass      = LabelCompassEnum.East;
                            lab.Connected    = true;
                            lab.Offset       = 10;
                            lab.AttachMethod = AttachMethodEnum.DataIndex;
                            lab.AttachMethodData.GroupIndex  = 0;
                            lab.AttachMethodData.SeriesIndex = s;
                            lab.AttachMethodData.PointIndex  = p;
                            lab.Style.BackColor = Color.Transparent;
                        }
                        lab.Text    = newLabText;
                        lab.Visible = true;
                    }
                }
            }
        }
        private void c1Chart1_Click(object sender, System.EventArgs e)
        {
            Point p = Control.MousePosition;

            // Convert to client coordinates
            p = c1Chart1.PointToClient(p);

            int si = -1; int d = -1;

            // Find the distance
            if (c1Chart1.ChartGroups[0].CoordToSeriesIndex(p.X, p.Y, PlotElementEnum.Series, ref si, ref d))
            {
                if (d <= 3)                  // if close enough
                {
                    if (si != selectedIndex) // Another index
                    {
                        if (selectedIndex != -1)
                        {
                            // Change series color and width to the default
                            ChartDataSeries ds = c1Chart1.ChartGroups[0].ChartData[selectedIndex];
                            ds.LineStyle.Color     = clrs[selectedIndex];
                            ds.LineStyle.Thickness = 1;
                        }

                        selectedIndex = si;
                        if (selectedIndex != -1)
                        {
                            // Change series color and width to indicate selection
                            ChartDataSeries ds = c1Chart1.ChartGroups[0].ChartData[selectedIndex];
                            ds.LineStyle.Color     = selectionColor;
                            ds.LineStyle.Thickness = 2;
                        }

                        // Show status label
                        if (selectedIndex < 0)
                        {
                            label1.Text = "Selection: none";
                        }
                        else
                        {
                            label1.Text = "Selection: " + c1Chart1.ChartGroups[0].ChartData[selectedIndex].Label;
                        }
                    }
                }
            }
        }
        private void c1Chart1_ShowTooltip(object sender, C1.Win.C1Chart.ShowTooltipEventArgs e)
        {
            // Select item in combobox
            if (sender.Equals(c1Chart1.Header))
            {
                comboBox1.SelectedItem = "Header";
            }
            else if (sender.Equals(c1Chart1.Footer))
            {
                comboBox1.SelectedItem = "Footer";
            }
            else if (sender.Equals(c1Chart1.ChartArea.AxisX))
            {
                comboBox1.SelectedItem = "X-axis";
            }
            else if (sender.Equals(c1Chart1.ChartArea.AxisY))
            {
                comboBox1.SelectedItem = "Y-axis";
            }
            else if (sender is ChartDataSeries)
            {
                // Create new tooltip text
                if (c1Chart1.ToolTip.PlotElement == PlotElementEnum.Series)
                {
                    ChartDataSeries ds = (ChartDataSeries)sender;

                    Point p = Control.MousePosition;
                    p = c1Chart1.PointToClient(p);

                    double x = 0, y = 0;

                    // Callculate data coordinates
                    if (ds.Group.CoordToDataCoord(p.X, p.Y, ref x, ref y))
                    {
                        e.TooltipText = string.Format("{0}\nx = {1:#.##}\ny = {2:#.##}", ds.Label, x, y);
                    }
                    else
                    {
                        e.TooltipText = "";
                    }
                }

                comboBox1.SelectedItem = "DataSeries";
            }
        }