Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Multiple Y Axis (Read 3143 times)
hyper
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Apr 8th, 2021
Multiple Y Axis
Apr 8th, 2021 at 5:48pm
Print Post  
Hi,

Winforms charting; not WPF.

I need to add a secondary Y Axis and bind it to a new realtime timeseries data series, which I already have working
in an existing Winforms chart; the new Y Axis will share the X Axis with the other times series I have, but have different
scaling, and exist alongside the existing Y Axis of course.

Can that be done with the Winforms package?  I'm not seeing
any obvious solutions in the examples I have found so far.

hyper
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Multiple Y Axis
Reply #1 - Apr 9th, 2021 at 7:46am
Print Post  
Hi,

Check the Samples\CSharp\MultipleAxes sample project installed with the control. It creates an Axis object defining the range, and then assigns it to YAxis property of series renderers, and passes it to YAxisRenderer constructor. The project uses the dashboard layout API to implement that.

If you prefer using a pre-configured chart control such as LineChart, you should be able to add series-renderer objects to Chart.Plot.SeriesRenderers, and axis-renderer objects to ChartPanel -

Code
Select All
var y2Axis = new YAxisRenderer(newYAxis, lineChart.XAxis);
y2Axis.GridColumn = 2;
y2Axis.PlotLeftSide = false;
y2Axis.GridRow = 0;
y2Axis.LabelsSource = lineChart.Plot;

lineChart.ChartPanel.Columns.Add(new GridColumn());
lineChart.ChartPanel.Children.Add(y2Axis); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
hyper
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Apr 8th, 2021
Re: Multiple Y Axis
Reply #2 - Apr 13th, 2021 at 11:26pm
Print Post  
Yes, I used DateTimeSeries example as my starting
point.

It doesn't use Series2D and there's also no explicit
assignment of the common Y axis, which my multiple
existing series are using, and things work fine.

I am a newly licensed newbie to Mindfusion, so just getting
up to speed.  I don't have your class object model understood.

Your code above works fine, and the new Y axis appears on the
right side of the chart; but what I am missing is how I can
assign one of my existing series to use this new Y Axis?

I am tied into using the LineChart based on that time series
example code.

Code
Select All
            YAxisRenderer yAxis2 = new YAxisRenderer(lineChart.XAxis);
            yAxis2.GridColumn = 2;
            yAxis2.PlotLeftSide = false;
            yAxis2.GridRow = 0;
            yAxis2.LabelsSource = lineChart.Plot;
            lineChart.ChartPanel.Columns.Add(new GridColumn());
            lineChart.ChartPanel.Children.Add(yAxis2);

 



hyper


  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Multiple Y Axis
Reply #3 - Apr 14th, 2021 at 9:15am
Print Post  
Series are associated with axis through a SeriesRenderer (e.g. that could let you draw different ranges from same series in same plot). So you will also need to add a second SeriesRenderer to the plot; the code for that specifically in DateTimeSeries example could look like that:

Code
Select All
// defines values range; if not specified, range will be calculated from series
var axis2 = new Axis();
axis2.MinValue = 0;
axis2.MaxValue = 30000;

// series that will be mapped to second Y axis
var values2 = new double[10] { 10000, 25000, 5000, 15000, 20000, 10000, 5000, 10000, 25000, 5000 };
var values3 = new double[10] { 20000, 15000, 15000, 10000, 25000, 5000, 15000, 20000, 5000, 15000 };
var series2 = new MindFusion.Charting.DateTimeSeries(
    years, values2, years[0], years[years.Length - 1]);
var series3 = new MindFusion.Charting.DateTimeSeries(
    years, values3, years[0], years[years.Length - 1]);
series2.MinValue = series3.MinValue = series.MinValue; // for scaling dates to values
series2.MaxValue = series3.MaxValue = series.MaxValue; // for scaling dates to values
series2.DateTimeFormat = series3.DateTimeFormat = series.DateTimeFormat;
series2.CustomDateTimeFormat = series3.CustomDateTimeFormat = series.CustomDateTimeFormat;

var data2 = new ObservableCollection<Series>();
data2.Add(series2);
data2.Add(series3);

// render second Y axis
var yAxis2 = new YAxisRenderer(axis2, areaChart.XAxis);
yAxis2.GridColumn = 2;
yAxis2.PlotLeftSide = false;
yAxis2.GridRow = 0;
yAxis2.LabelsSource = areaChart.Plot;
areaChart.ChartPanel.Columns.Add(new GridColumn());
areaChart.ChartPanel.Children.Add(yAxis2);

// render second Y's series
var areaRenderer2 = new AreaRenderer(data2);
areaRenderer2.YAxis = axis2;
areaChart.Plot.SeriesRenderers.Add(areaRenderer2); 



You could as well add a different type of chart graphics for the second axis, say bars or lines, regardless of base control being AreaChart:

Code
Select All
// render second Y's series
var barRenderer2 = new BarRenderer(data2);
barRenderer2.YAxis = axis2;
areaChart.Plot.SeriesRenderers.Add(barRenderer2); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
hyper
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Apr 8th, 2021
Re: Multiple Y Axis
Reply #4 - Apr 14th, 2021 at 4:48pm
Print Post  
THANK YOU.
THAT GIVES ME A GREAT START !
hyper
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint