Page 1 of 1

How to scale a complete serie example kWh -> MWh

Posted: Fri Mar 10, 2006 10:43 am
by 8120407
Hello,

I have a chart with a couple of series in it.
This serie are based on a Unit of Measurement (uom) like kWh.

We want to rescale the complete serie to a other unit MWh, so we need to recalc the complete serie and multiply each value by 0.001.

This works correct but the axis are not scaled.

For example we have a left axis from 0 to 60.000 kWh rescale to MWh it must be 0 to 60 Mwh. The chart scales but the axis scales not. What we expect is that the chart looks like the same only the axis values changed.

Must we set again the min and max values for the chart.
Old min/max values multiply by a factor

The problem is how to get the correct min max value's. Are those the min / max of the Yvalues. or the min/max of the series or min/max of the axes (getVertAxis). They are a different and we never find a value of the values that are showed on the axis.

Can you provide me of a example.

With regard,

Roland Hillebrand

Posted: Fri Mar 10, 2006 10:59 am
by narcis
Hi Roland,

You can do something like the code below where button1 changes series units and. Calling axis Invalidate method it is redrawn and thus recalculated adopting new series values.

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)			
		{
			for (int i=0;i<100;++i) line1.Add(i*1000);
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			for (int i=0;i<line1.Count;++i) line1.YValues[i]=line1.YValues[i]/1000;
			tChart1.Axes.Left.Invalidate();
		}

Posted: Fri Mar 10, 2006 11:10 am
by 8120407
Narcis,

Thanks for the fast response.

This is what we do but we have set the left axis to a min and a max value. The data in the chart has a periode where the values are higher then the max value of the left axis.

Then it looks like it didn't work any more. When we set the left axis to automatic max then it works, but the window (min /max) is then to big.

Must we first set it to auto and then back to a min and max value calculated by the previous min/max of the shown left axis. Are those to read out before we do a rescale of the chart.

By the way we use this in a cached chart (asp.Net 1.1).

With regards,

Roland Hillebrand

Posted: Fri Mar 10, 2006 11:16 am
by narcis
Hi Roland,

Could you please send us an example we can run "as-is" to reproduce the problem here and try to provide you a solution for it?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup.

Thanks in advance.

Posted: Fri Mar 10, 2006 11:38 am
by 8120407
Narcis,

A working example is difficult to make at the moment. Maybe if I provide the code you can see my problem. If not, i go the make the sample.

Code: Select all

private static void UpdateCaptionsAxes(WebChart chartToUpdate ,int serieNr, string uom, double factor)
            {
                string oldName =  chartToUpdate.Chart.Series[serieNr].GetVertAxis.Title.Caption ;   
                
                // replace uom is place between ()
                chartToUpdate.Chart.Series[serieNr].CustomVertAxis.Labels.CustomSize = 41;  
                chartToUpdate.Chart.Series[serieNr].GetVertAxis.Title.Caption = oldName.Replace(Between(oldName,'(',')',1),uom);
                
                double min = chartToUpdate.Chart.Series[serieNr].GetVertAxis.Minimum * factor;  // How to get the correct shown min
                double max = chartToUpdate.Chart.Series[serieNr].GetVertAxis.Maximum * factor;// How to get the correct shown, max

                chartToUpdate.Chart.Series[serieNr].GetVertAxis.SetMinMax(min,max);
 
            }
With regards,

Roland Hillebrand

Posted: Fri Mar 10, 2006 12:12 pm
by 8120407
Narcis,

I found the solution.

Code: Select all

 private static void UpdateCaptionsAxes(WebChart chartToUpdate ,int serieNr, string uom, double factor)
            {
                 
                // rescale left axis
                if (chartToUpdate.Chart.Series[serieNr].Chart.Axes.Left.Automatic == false ||
                    chartToUpdate.Chart.Series[serieNr].GetVertAxis.Automatic == false)
                {
                    double min = chartToUpdate.Chart.Series[serieNr].Chart.Axes.Left.Minimum* factor ; 
                    double max = chartToUpdate.Chart.Series[serieNr].Chart.Axes.Left.Maximum * factor;
                
                    chartToUpdate.Chart.Series[serieNr].Chart.Axes.Left.SetMinMax(min,max);
                    chartToUpdate.Chart.Series[serieNr].GetVertAxis.SetMinMax(min,max);
                }

                // replace uom is place between ()
                string oldName =  chartToUpdate.Chart.Series[serieNr].GetVertAxis.Title.Caption ;  
                chartToUpdate.Chart.Series[serieNr].CustomVertAxis.Labels.CustomSize = 41;  
                chartToUpdate.Chart.Series[serieNr].GetVertAxis.Title.Caption = oldName.Replace(Between(oldName,'(',')',1),uom);
            }
But why do I need to set them both GetVertAxis and left.
Are they not the same !??

With regards,

Roland Hillebrand

Posted: Fri Mar 10, 2006 12:43 pm
by narcis
Hi Roland,
But why do I need to set them both GetVertAxis and left.
Are they not the same !??
Yes, they are the same if you use the default axes and don't change your series vertical axis. If that's your case you should try only scaling Left axis.