Skip to content

Commit 9969a3b

Browse files
docs(chart): add example for moving value axis to the right
1 parent e1c412b commit 9969a3b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
18.9 KB
Loading

components/chart/multiple-axes.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ You can have the chart render more than one axis for a given dimension. This let
1616
1717
![](images/multiple-y-axes.png)
1818

19+
>tip The [Examples](#examples) section offer several common use-cases.
20+
1921
This article contains the following sections:
2022

2123
* [Define Multiple Axes](#define-multiple-axes)
@@ -28,6 +30,7 @@ This article contains the following sections:
2830
* [Behavior with Bar and Column Charts](#behavior-with-bar-and-column-charts)
2931
* [Numerical Chart Examples](#numerical-chart-examples)
3032
* [Move X-Axis Labels to the Bottom](#move-x-axis-labels-to-the-bottom)
33+
* [Move Value Axis to the Right](#move-value-axis-to-the-right)
3134

3235
>tip When using multiple axes, you would often set the color of the axis to match the `Color` of the series that uses it.
3336
@@ -72,6 +75,7 @@ In this section you can find code examples, explanations on the behavior and scr
7275
* [Behavior with Bar and Column Charts](#behavior-with-bar-and-column-charts)
7376
* [Numerical Chart Examples](#numerical-chart-examples)
7477
* [Move X-Axis Labels to the Bottom](#move-x-axis-labels-to-the-bottom)
78+
* [Move Value Axis to the Right](#move-value-axis-to-the-right)
7579

7680

7781
### Categorical Chart - Value Axes Examples
@@ -502,6 +506,78 @@ The general approach is to set an axis crossing point that has a very large valu
502506
![](images/x-axis-labels-at-bottom.png)
503507

504508

509+
### Move Value Axis to the Right
510+
511+
To ensure that an axis is always to the desired side of the chart, you could set its corresponding `AxisCrossingValue` to a very large value such as `int.MaxValue` or `int.MinValue`.
512+
513+
This approach can work for both numerical and categorical axes. The example below uses a categorical axis.
514+
515+
>caption Example of setting a crossing point that is very large so the value axis appears on the right hand side of the chart
516+
517+
````CSHTML
518+
@* See the AxisCrossingValue parameter on the x-axis and its value - it uses int.MaxValue to push the second value axis all the way to the right *@
519+
520+
<TelerikChart>
521+
522+
<ChartCategoryAxes>
523+
<ChartCategoryAxis AxisCrossingValue="@crossingValues" BaseUnit="ChartCategoryAxisBaseUnit.Days" Type="ChartCategoryAxisType.Date">
524+
</ChartCategoryAxis>
525+
</ChartCategoryAxes>
526+
527+
<ChartValueAxes>
528+
<ChartValueAxis Type="@ChartValueAxisType.Numeric" Name="FirstYAxis" Visible="true">
529+
<ChartValueAxisLabels Template="#=value# kWh" Visible="true"></ChartValueAxisLabels>
530+
</ChartValueAxis>
531+
532+
<ChartValueAxis Type="@ChartValueAxisType.Numeric" Name="SecondYAxis" Visible="true">
533+
<ChartValueAxisLabels Template="#=value# kWh" Visible="true"></ChartValueAxisLabels>
534+
</ChartValueAxis>
535+
</ChartValueAxes>
536+
537+
<ChartSeriesItems>
538+
<ChartSeries Type="ChartSeriesType.Column" Name="Product 1 (SUM)" Data="@chartData" Field="@nameof(MyDataModel.Product1)" CategoryField="@nameof(MyDataModel.MySharedCategories)" Aggregate="ChartSeriesAggregate.Sum" Axis="FirstYAxis">
539+
<ChartSeriesLabels Visible="false"></ChartSeriesLabels>
540+
<ChartSeriesTooltip Visible="true"></ChartSeriesTooltip>
541+
</ChartSeries>
542+
<ChartSeries Type="ChartSeriesType.Column" Name="Product 2 (SUM)" Data="@chartData" Field="@nameof(MyDataModel.Product2)" CategoryField="@nameof(MyDataModel.MySharedCategories)" Aggregate="ChartSeriesAggregate.Sum" Axis="SecondYAxis">
543+
<ChartSeriesLabels Visible="false"></ChartSeriesLabels>
544+
<ChartSeriesTooltip Visible="true"></ChartSeriesTooltip>
545+
</ChartSeries>
546+
</ChartSeriesItems>
547+
548+
</TelerikChart>
549+
550+
@code {
551+
public object[] crossingValues = new object[] { 0, int.MaxValue };
552+
553+
public class MyDataModel
554+
{
555+
public DateTime MySharedCategories { get; set; }
556+
public decimal Product1 { get; set; }
557+
public decimal Product2 { get; set; }
558+
}
559+
560+
public List<MyDataModel> chartData = new List<MyDataModel>();
561+
562+
protected override void OnInitialized()
563+
{
564+
var random = new Random();
565+
566+
for (var i = 0; i < 10; i++)
567+
{
568+
var dateTime = new DateTime(2019, 1, 1);
569+
var value1 = Convert.ToDecimal(random.NextDouble() * 10);
570+
var value2 = Convert.ToDecimal(random.NextDouble() * 10);
571+
this.chartData.Add(new MyDataModel { MySharedCategories = dateTime.AddDays(i), Product1 = value1, Product2 = value2 });
572+
}
573+
}
574+
}
575+
````
576+
577+
>caption The result from the code snippet above
578+
579+
![Move the second value axis to the right](images/chart-crossing-value-axis-to-the-right.png)
580+
505581

506582
## See Also
507583

0 commit comments

Comments
 (0)