-1

I'm new to mschart and facing some problems. I read records from database and plot them on chart. The problems are:

  1. Chart only gets plotted when I set the maximum record value as the maximum y-axis value. If I try to set the maximum value of y-axis like maximum + 50, my chart is plotting it wrong. Here is my code:

        double y = 0;
        foreach (Record record in records)
        {
            if (y < record.HighValue)
                y = record.HighValue;
        }
    
        chart.ChartAreas["draw"].AxisY2.Minimum = 0;
        chart.ChartAreas["draw"].AxisY2.Maximum = y;
        chart.ChartAreas["draw"].AxisY2.Interval = y / 10;
    
        Series s = new Series();
        s.Name = seriesName;
        s.IsXValueIndexed = true;
        s.XValueType = ChartValueType.Date;
        s.ChartType = SeriesChartType.Candlestick;
        s.Color = Color.Black;
    
        s["OpenCloseStyle"] = "Triangle";
        s["ShowOpenClose"] = "Both";
        s["PointWidth"] = "1.0";
        s["PriceUpColor"] = "Black";
    
        chart.Series.Add(s);
    
        for (int i = 0; i < records.Count; i++)
        {
            s.Points.AddXY(records[i].CurrentDate, records[i].HighValue);
            s.Points[i].YValues[1] = records[i].LowValue;
            s.Points[i].YValues[2] = records[i].OpenValue;
            s.Points[i].YValues[3] = records[i].CloseValue;
        }
    

The chart is displayed like this:

Now if I try to change the maximum y-axis value like:

        chart.ChartAreas["draw"].AxisY2.Maximum = y*2;

The plot is something like this:

Now this is wrong as you can see the series is at wrong y-axis location

  1. The second problem I face is when I zoom the chart, x-axis is getting zoomed but I couldn't zoom y-axis. I tried this thread but couldn't get what is 'Zoom-x-value'

MSChart - Auto Zoom Y Axis on X Axis Zoom

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Ashutosh
  • 4,371
  • 10
  • 59
  • 105

1 Answers1

0

Question 1 Probable Solution: Your code doesn't say you are setting the series to align to the secondary Y axis. You need to add this line of code:

s.YAxisType = AxisType.Secondary;

The problem you are having with question 2 may be related to my proposed solution to question 1, but I don't have a lot of firsthand experience with using zooming on mschart objects. Please elaborate on what you mean by 'isn't zooming'. Do you mean the y-axis values aren't changing? or the data itself is not being zoomed in on visually?

Edit 1: (Based on follow up comment) If you are setting the minimum, maximum, or interval Y axis values yourself during the zoom step, make sure you are setting the AxisY2.Minimum, AxisY2.Maximum, AxisY2.Interval as the axis displayed in the chart above is the Y2 axis, not the Y. The Y2 axis the axis on the right of the chart, and the AxisX2 is the x-axis displayed at the top of the chart. (X2 and Y2 are disabled by default usually, but you have Y2 displaying values in your image above, hence the need to bind you series to the AxisType.Secondary)

Edit 2: (Based on search regarding zooming with secondary axis) See Link: How to zoom secondary y axis in mschart

Community
  • 1
  • 1
JHubbard80
  • 2,217
  • 1
  • 20
  • 24
  • By zooming I mean y-axis will contain only those minimum and maximum values which covers the current range of chart. For example, the whole chart has min=100 and max=500. Now when I zoom to a particular part, let us say that min=350 and max=450 for this part, then these values should be min and max for chart – Ashutosh Dec 09 '14 at 10:58
  • Once you associate the series with the correct axis as I describe above, MSChart zooming should behave properly. Let me know if you set the axis type properly and if it continues to have zoom issues and I will make a mockup to investigate further when time allows. If you are doing anything yourself with setting the Min and Max, make sure you are assigning AxisY2.Minimum and AxisY2.Maximum. (The '2' denotes you are using the axis on the top instead of bottom for X, or the axis on right of the chart versus left of the chart for Y) – JHubbard80 Dec 10 '14 at 18:39