|
6 | 6 | var barGraphColors = StaticHelper.GetBarChartColors(); |
7 | 7 | var userConfig = config.GetUserConfig(User); |
8 | 8 | var userLanguage = userConfig.UserLanguage; |
9 | | - |
| 9 | +} |
| 10 | +@if (Model.CostData.Any(x => x.Cost > 0)) |
| 11 | +{ |
| 12 | + var chartMax = Math.Ceiling(Model.CostData.Max(x => x.Cost)); |
10 | 13 | var graphGrace = Decimal.ToInt32(Model.CostData.Max(x => x.Cost) - Model.CostData.Min(x => x.Cost)); |
11 | | - if (graphGrace < 0 || Model.CostData.Min(x=>x.Cost) - graphGrace < 0) |
| 14 | + var chartMin = Math.Floor(Model.CostData.Min(x => x.Cost) - graphGrace); |
| 15 | + if (graphGrace < 0 || chartMin < 0) |
12 | 16 | { |
13 | 17 | graphGrace = 0; |
| 18 | + chartMin = 0; |
| 19 | + } |
| 20 | + var stepSize = StaticHelper.CalculateNiceStepSize(chartMin, chartMax, 8); |
| 21 | + var remMin = stepSize > 0 ? chartMin % stepSize : 0; |
| 22 | + var cleanedMin = chartMin - remMin; |
| 23 | + if (remMin >= (stepSize / 2)) |
| 24 | + { |
| 25 | + cleanedMin += stepSize; |
| 26 | + } |
| 27 | + var remMax = stepSize > 0 ? chartMax % stepSize : 0; |
| 28 | + var cleanedMax = chartMax - remMax; |
| 29 | + if (remMax >= (stepSize / 2)) |
| 30 | + { |
| 31 | + cleanedMax += stepSize; |
14 | 32 | } |
15 | | -} |
16 | | -@if (Model.CostData.Any(x => x.Cost > 0)) |
17 | | -{ |
18 | 33 | <canvas id="bar-chart-mpg"></canvas> |
19 | 34 | <script> |
20 | 35 | renderChart(); |
|
60 | 75 | scales: { |
61 | 76 | y: { |
62 | 77 | beginAtZero: false, |
63 | | - grace: decodeHTMLEntities('@(graphGrace)'), |
| 78 | + max: Math.ceil(decodeHTMLEntities('@(cleanedMax)')), |
| 79 | + min: Math.floor(decodeHTMLEntities('@(cleanedMin)')), |
64 | 80 | ticks: { |
65 | | - color: useDarkMode ? "#fff" : "#000" |
| 81 | + color: useDarkMode ? "#fff" : "#000", |
| 82 | + stepSize: Math.ceil(decodeHTMLEntities('@(stepSize)')) |
66 | 83 | } |
67 | 84 | }, |
68 | 85 | x: { |
|
0 commit comments