Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I have a chart at the moment that carries quite a lot of data. This can be seen in the image below:

enter image description here

Basically I want the user to be able to zoom in and see further into the data. As you can tell it is currently carrying a large amount of data already.

I would like the user to be able to zoom and see more precise things.

protected void drawChart()
    {


        DataTable dt = new DataTable();
        dt.Clear();

        foreach (DataGridViewColumn col in dataGridView1.Columns)
        {
            dt.Columns.Add(col.HeaderText);
        }

        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            DataRow dRow = dt.NewRow();
            foreach (DataGridViewCell cell in row.Cells)
            {
                dRow[cell.ColumnIndex] = cell.Value;
            }
            dt.Rows.Add(dRow);
        }


        chart1.DataBind();

        chart1.DataSource = dt;
        chart1.ChartAreas[0].AxisX.IntervalAutoMode = 
                             IntervalAutoMode.VariableCount;
        chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
        chart1.Series["Series1"].XValueMember = "Date/Time";

        chart1.Series["Series1"].YValueMembers = "HeartRate";

        chart1.Series["Series2"].ChartType = SeriesChartType.Line;
        chart1.Series["Series2"].YValueMembers = "Speed";

        chart1.Series["Series3"].ChartType = SeriesChartType.Line;
        chart1.Series["Series3"].YValueMembers = "Cadence";

        chart1.Series["Series4"].ChartType = SeriesChartType.Line;
        chart1.Series["Series4"].YValueMembers = "Altitude";

        chart1.Series["Series5"].ChartType = SeriesChartType.Line;
        chart1.Series["Series5"].YValueMembers = "Pressure";

        chart1.Series["Series6"].ChartType = SeriesChartType.Line;
        chart1.Series["Series6"].YValueMembers = "Power";

        chart1.Series["Series1"].LegendText = "Heart Rate";

        chart1.Series["Series1"].ToolTip =
         "Heart Rate:#VALY
Average:#AVG
Minimum:#MIN
Maximum:#MAX ";

        chart1.Series["Series2"].LegendText = "Speed";
        chart1.Series["Series2"].ToolTip = 
         "Speed(KM/H):#VALY
Average:#AVG
Maximum:#MAX";

        chart1.Series["Series3"].LegendText = "Cadence";
        chart1.Series["Series3"].ToolTip = 
         "Cadence:#VALY
Average:#AVG
Maximum:#MAX";

        chart1.Series["Series4"].LegendText = "Altitude";
        chart1.Series["Series4"].ToolTip =  
         "Altitude(KM/H):#VALY
Average:#AVG
Maximum:#MAX";

        chart1.Series["Series5"].LegendText = "Pressure";
        chart1.Series["Series5"].ToolTip = 
         "Pressure:#VALY
Average:#AVG
Maximum:#MAX";

        chart1.Series["Series6"].LegendText = "Power";
        chart1.Series["Series6"].ToolTip = 
          "Power:#VALY
Average:#AVG
Maximum:#MAX";

        // add the highlight series after databinding!! (**)
        Series sz = chart1.Series.Add("Interval");
        sz.ChartType = SeriesChartType.Point;
        sz.Color = Color.Red;
        sz.BorderWidth = 3;

        foreach (DataPoint dp in chart1.Series[0].Points)
        {
            if (dp.YValues[0] == 0) sz.Points.AddXY(dp.XValue, 0);
        }

        // allow zooming: (Taw's edit)
        chart1.Series["Series1"].AxisX.ScaleView.Zoomable = true;
        chart1.Series["Series1"].CursorX.AutoScroll = true;
        chart1.Series["Series1"].CursorX.IsUserSelectionEnabled = true;          


   }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
468 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is easy but it does take a few settings to do the trick:

ChartArea CA = chart1.ChartAreas[0];  // quick reference
CA.AxisX.ScaleView.Zoomable = true;
CA.CursorX.AutoScroll = true;
CA.CursorX.IsUserSelectionEnabled = true;

Now the user can drag the mouse over an area of interest and it will be zoomed in to fill the Chart:

enter image description hereenter image description here

Note the small button on the left of the horizontal scrollbar: This resets the range.

As ever so often with Chart the problem is the not exactly well structured documentation..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...