Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

add a property which can set the axis' AxisType #1075

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Core/AxisCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public AxisCore(IAxisView view)
#endregion

#region Public Properties

/// <summary>
/// Gets or sets the axistype
/// </summary>
public AxisType AxisType { get; set; }
/// <summary>
/// Gets or sets the chart.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions Core/AxisType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace LiveCharts
{
/// <summary>
/// Axis type
/// </summary>
public enum AxisType
{
/// <summary>
/// actual
/// </summary>
Actual,

/// <summary>
/// per
/// </summary>
Per,
}
}
4 changes: 2 additions & 2 deletions Core/Charts/CartesianChartCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void PrepareAxes()
xi.CalculateSeparator(this, AxisOrientation.X);

// ReSharper disable once AccessToModifiedClosure
SetAxisLimits(xi, cartesianSeries.Where(x => x.View.ScalesXAt == index).ToArray(), AxisOrientation.X);
SetAxisLimits(xi, cartesianSeries.Where(x => x.View.ScalesXAt == (int)AxisY[index].AxisType).ToArray(), AxisOrientation.X);

if (Math.Abs(xi.BotLimit - xi.TopLimit) < xi.S * .01)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public override void PrepareAxes()
yi.CalculateSeparator(this, AxisOrientation.Y);

// ReSharper disable once AccessToModifiedClosure
SetAxisLimits(yi, cartesianSeries.Where(x => x.View.ScalesYAt == index).ToArray(), AxisOrientation.Y);
SetAxisLimits(yi, cartesianSeries.Where(x => x.View.ScalesYAt == (int)AxisY[index].AxisType).ToArray(), AxisOrientation.Y);

if (Math.Abs(yi.BotLimit - yi.TopLimit) < yi.S * .01)
{
Expand Down
38 changes: 19 additions & 19 deletions Core/Charts/ChartCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public virtual void PrepareAxes()
AxisX[index],
View.ActualSeries
// ReSharper disable once AccessToModifiedClosure
.Where(series => series.Values != null && series.ScalesXAt == index).ToArray(),
.Where(series => series.Values != null && series.ScalesXAt == (int)AxisY[index].AxisType).ToArray(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like you've not reviewed your own code.

AxisOrientation.X);
}

Expand All @@ -212,7 +212,7 @@ public virtual void PrepareAxes()
AxisY[index],
View.ActualSeries
// ReSharper disable once AccessToModifiedClosure
.Where(series => series.Values != null && series.ScalesYAt == index).ToArray(),
.Where(series => series.Values != null && series.ScalesYAt == (int)AxisY[index].AxisType).ToArray(),
AxisOrientation.Y);
}
}
Expand All @@ -222,7 +222,7 @@ public virtual void PrepareAxes()
/// </summary>
public virtual void RunSpecializedChartComponents()
{

}

/// <summary>
Expand Down Expand Up @@ -258,10 +258,10 @@ public void CalculateComponentsAndMargin()
ax.Tab = curSize.Left + curSize.Width;
}

var uw = ax.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(AxisOrientation.Y, this, index)/2 : 0;
var uw = ax.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(AxisOrientation.Y, this, index) / 2 : 0;

var topE = biggest.Top - uw;
if (topE> curSize.Top)
if (topE > curSize.Top)
{
var dif = topE - curSize.Top;
curSize.Top += dif;
Expand Down Expand Up @@ -298,7 +298,7 @@ public void CalculateComponentsAndMargin()
}

//Notice the unit width is not exact at this point...
var uw = xi.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(AxisOrientation.X, this, index)/2 : 0;
var uw = xi.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(AxisOrientation.X, this, index) / 2 : 0;

var leftE = biggest.Left - uw > 0 ? biggest.Left - uw : 0;
if (leftE > curSize.Left)
Expand Down Expand Up @@ -342,7 +342,7 @@ public void CalculateComponentsAndMargin()
ax.TopLimit -= pr;
}
ax.UpdateSeparators(AxisOrientation.Y, this, index);
ax.View.SetTitleTop(curSize.Top + curSize.Height*.5 + ax.View.GetLabelSize().Width*.5);
ax.View.SetTitleTop(curSize.Top + curSize.Height * .5 + ax.View.GetLabelSize().Width * .5);
}

for (var index = 0; index < AxisX.Count; index++)
Expand All @@ -356,7 +356,7 @@ public void CalculateComponentsAndMargin()
xi.TopLimit += pr;
}
xi.UpdateSeparators(AxisOrientation.X, this, index);
xi.View.SetTitleLeft(curSize.Left + curSize.Width*.5 - xi.View.GetLabelSize().Width*.5);
xi.View.SetTitleLeft(curSize.Left + curSize.Width * .5 - xi.View.GetLabelSize().Width * .5);
}
}

Expand All @@ -383,19 +383,19 @@ public CoreRectangle PlaceLegend(CoreRectangle drawMargin)
View.ShowLegend(new CorePoint(ControlSize.Width * .5 - legendSize.Width * .5, 0));
break;
case LegendLocation.Bottom:
var bot = new CorePoint(ControlSize.Width*.5 - legendSize.Width*.5,
var bot = new CorePoint(ControlSize.Width * .5 - legendSize.Width * .5,
ControlSize.Height - legendSize.Height);
drawMargin.Height -= legendSize.Height;
View.ShowLegend(new CorePoint(bot.X, ControlSize.Height - legendSize.Height));
break;
case LegendLocation.Left:
drawMargin.Left = drawMargin.Left + legendSize.Width;
View.ShowLegend(new CorePoint(0, ControlSize.Height*.5 - legendSize.Height*.5));
View.ShowLegend(new CorePoint(0, ControlSize.Height * .5 - legendSize.Height * .5));
break;
case LegendLocation.Right:
drawMargin.Width -= legendSize.Width + padding;
View.ShowLegend(new CorePoint(ControlSize.Width - legendSize.Width,
ControlSize.Height*.5 - legendSize.Height*.5));
ControlSize.Height * .5 - legendSize.Height * .5));
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down Expand Up @@ -488,7 +488,7 @@ public void ZoomOut(CorePoint pivot)

var target = l * (1 / speed);
if (target > xi.View.MaxRange) return;
var mint = px- target * rMin;
var mint = px - target * rMin;
var maxt = px + target * rMax;
xi.View.SetRange(mint, maxt);
}
Expand All @@ -501,7 +501,7 @@ public void ZoomOut(CorePoint pivot)
var ax = AxisY[index];

var py = ChartFunctions.FromPlotArea(pivot.Y, AxisOrientation.Y, this, index);

var max = double.IsNaN(ax.View.MaxValue) ? ax.TopLimit : ax.View.MaxValue;
var min = double.IsNaN(ax.View.MinValue) ? ax.BotLimit : ax.View.MinValue;
var l = max - min;
Expand Down Expand Up @@ -672,13 +672,13 @@ public void Drag(CorePoint delta)
if (double.IsNaN(ax.MinValue))
ax.BotLimit = mostLeft == 0.0
? 0.0
: Math.Floor(mostLeft/ax.S)*ax.S;
: Math.Floor(mostLeft / ax.S) * ax.S;
if (mostRight > ax.TopLimit)
// ReSharper disable once CompareOfFloatsByEqualityOperator
if (double.IsNaN(ax.MaxValue))
ax.TopLimit = mostRight == 0.0
? 0.0
: (Math.Floor(mostRight/ax.S) + 1.0) *ax.S;
: (Math.Floor(mostRight / ax.S) + 1.0) * ax.S;
}
}

Expand All @@ -698,13 +698,13 @@ public void Drag(CorePoint delta)
if (double.IsNaN(ay.MinValue))
ay.BotLimit = mostLeft == 0.0
? 0.0
: Math.Floor(mostLeft/ay.S)*ay.S;
: Math.Floor(mostLeft / ay.S) * ay.S;
if (mostRight > ay.TopLimit)
// ReSharper disable once CompareOfFloatsByEqualityOperator
if (double.IsNaN(ay.MaxValue))
ay.TopLimit = mostRight == 0.0
? 0.0
: (Math.Floor(mostRight/ay.S) + 1.0) *ay.S;
: (Math.Floor(mostRight / ay.S) + 1.0) * ay.S;
}
}
}
Expand All @@ -725,9 +725,9 @@ private static void SetAxisLimits(AxisCore ax, IList<ISeriesView> series, AxisOr
var view = series[0] as IAreaPoint;
firstR = view != null ? view.GetPointDiameter() : 0;
}

// [ max, min, pointRadius ]
var boundries = new[] {first.Max, first.Min, firstR};
var boundries = new[] { first.Max, first.Min, firstR };

for (var index = 1; index < series.Count; index++)
{
Expand Down
1 change: 1 addition & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Compile Include="AxisOrientation.cs" />
<Compile Include="AxisPosition.cs" />
<Compile Include="AxisSectionCore.cs" />
<Compile Include="AxisType.cs" />
<Compile Include="AxisWindow.cs" />
<Compile Include="AxisWindows.cs" />
<Compile Include="BarLabelPosition.cs" />
Expand Down
7 changes: 7 additions & 0 deletions Core/Definitions/Charts/IAxisView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ namespace LiveCharts.Definitions.Charts
/// </summary>
public interface IAxisView
{
/// <summary>
/// Get or sets the axis type
/// </summary>
/// <value>
/// The axis type
/// </value>
AxisType AxisType { get; set; }
/// <summary>
/// Gets or sets the model.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Core40/AxisCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public AxisCore(IAxisView view)
#endregion

#region Public Properties
/// <summary>
/// Gets or sets the axistype
/// </summary>
public AxisType AxisType { get; set; }

/// <summary>
/// Gets or sets the chart.
Expand Down
18 changes: 18 additions & 0 deletions Core40/AxisType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace LiveCharts
{
/// <summary>
/// Axis type
/// </summary>
public enum AxisType
{
/// <summary>
/// actual
/// </summary>
Actual,

/// <summary>
/// per
/// </summary>
Per,
}
}
4 changes: 2 additions & 2 deletions Core40/Charts/CartesianChartCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void PrepareAxes()
xi.CalculateSeparator(this, AxisOrientation.X);

// ReSharper disable once AccessToModifiedClosure
SetAxisLimits(xi, cartesianSeries.Where(x => x.View.ScalesXAt == index).ToArray(), AxisOrientation.X);
SetAxisLimits(xi, cartesianSeries.Where(x => x.View.ScalesXAt == (int)AxisX[index].AxisType).ToArray(), AxisOrientation.X);

if (Math.Abs(xi.BotLimit - xi.TopLimit) < xi.S * .01)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public override void PrepareAxes()
yi.CalculateSeparator(this, AxisOrientation.Y);

// ReSharper disable once AccessToModifiedClosure
SetAxisLimits(yi, cartesianSeries.Where(x => x.View.ScalesYAt == index).ToArray(), AxisOrientation.Y);
SetAxisLimits(yi, cartesianSeries.Where(x => x.View.ScalesYAt == (int)AxisY[index].AxisType).ToArray(), AxisOrientation.Y);

if (Math.Abs(yi.BotLimit - yi.TopLimit) < yi.S * .01)
{
Expand Down
4 changes: 2 additions & 2 deletions Core40/Charts/ChartCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public virtual void PrepareAxes()
AxisX[index],
View.ActualSeries
// ReSharper disable once AccessToModifiedClosure
.Where(series => series.Values != null && series.ScalesXAt == index).ToArray(),
.Where(series => series.Values != null && series.ScalesXAt == (int)AxisX[index].AxisType).ToArray(),
AxisOrientation.X);
}

Expand All @@ -213,7 +213,7 @@ public virtual void PrepareAxes()
AxisY[index],
View.ActualSeries
// ReSharper disable once AccessToModifiedClosure
.Where(series => series.Values != null && series.ScalesYAt == index).ToArray(),
.Where(series => series.Values != null && series.ScalesYAt == (int)AxisY[index].AxisType).ToArray(),
AxisOrientation.Y);
}
}
Expand Down
1 change: 1 addition & 0 deletions Core40/Core40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="AxisOrientation.cs" />
<Compile Include="AxisPosition.cs" />
<Compile Include="AxisSectionCore.cs" />
<Compile Include="AxisType.cs" />
<Compile Include="AxisWindow.cs" />
<Compile Include="AxisWindows.cs" />
<Compile Include="BarLabelPosition.cs" />
Expand Down
56 changes: 34 additions & 22 deletions Examples/Wpf/CartesianChart/MultiAxes/MultiAxesChart.xaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
<UserControl x:Class="Wpf.CartesianChart.MultiAxesChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl
x:Class="Wpf.CartesianChart.MultiAxesChart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
<Grid>
<Grid.Resources>
<Style x:Key="CleanSeparator" TargetType="lvc:Separator">
<Setter Property="IsEnabled" Value="False"></Setter>
<Setter Property="IsEnabled" Value="False" />
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" TextWrapping="Wrap">
You can create multiple axes, just set the Series.ScalesXAt or Series.ScalesYAt properties, you must also add the axis explicitly.
You can create multiple axes, just set the Series.ScalesXAt or Series.ScalesYAt properties, you must also add the axis explicitly, other you can set Axis' AxisType to convert the values as actual or per.
</TextBlock>
<lvc:CartesianChart Grid.Row="2">
<lvc:CartesianChart.AxisY>
<lvc:Axis Foreground="DodgerBlue" Title="Blue Axis"/>
<lvc:Axis Foreground="IndianRed" Title="Red Axis" Position="RightTop">
<lvc:Axis Title="Blue Axis" Foreground="DodgerBlue" />
<lvc:Axis
Title="Red Axis"
AxisType="Per"
Foreground="IndianRed"
Position="RightTop">
<lvc:Axis.Separator>
<lvc:Separator Style="{StaticResource CleanSeparator}"></lvc:Separator>
<lvc:Separator Style="{StaticResource CleanSeparator}" />
</lvc:Axis.Separator>
</lvc:Axis>
<lvc:Axis Foreground="DarkOliveGreen" Title="Green Axis" Position="RightTop">
<lvc:Axis
Title="Green Axis"
Foreground="DarkOliveGreen"
Position="RightTop">
<lvc:Axis.Separator>
<lvc:Separator Style="{StaticResource CleanSeparator}"></lvc:Separator>
<lvc:Separator Style="{StaticResource CleanSeparator}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.Series>
<lvc:LineSeries Values="1,5,3,5,3" ScalesYAt="0"/> <!--Scales at blue axis, Axis[0]-->
<lvc:LineSeries Values="20,30,70,20,10" ScalesYAt="1"/> <!--Scales at red axis, Axis[1]-->
<lvc:LineSeries Values="600,300,200,600,800" ScalesYAt="2"/> <!--Scales at green axis, Axis[2]-->
<lvc:LineSeries ScalesYAt="0" Values="1,5,3,5,3" />
<!-- Scales at blue axis, Axis[0] -->
<lvc:LineSeries ScalesYAt="1" Values="20,30,70,20,10" />
<!-- Scales at red axis, Axis[1] -->
<lvc:LineSeries ScalesYAt="2" Values="600,300,200,600,800" />
<!-- Scales at green axis, Axis[2] -->
</lvc:CartesianChart.Series>
</lvc:CartesianChart>
</Grid>
Expand Down
Loading