Charts with dates, how to handle output #5563
Replies: 3 comments
-
I've played a little with the settings and it seems that this should work. LineChartOptions lineChartOptions = new()
{
AspectRatio = 1.5,
Scales = new ChartScales
{
X = new ChartAxis
{
Type = "time",
Display = true,
Title = new()
{
Display = true,
Text = "Date",
},
Time = new ChartAxisTime
{
Unit = "day",
DisplayFormat = new()
{
Day = "DD T",
}
}
},
Y = new()
{
Title = new()
{
Display = true,
Text = "Hits"
},
},
},
}; The date format should math the chartjs formats, not the .NET. So you might need to play a bit until it works for your use cases. |
Beta Was this translation helpful? Give feedback.
-
I tried using your code and I'm receiving the following error. It looks like I was missing a chartjs adapter support script. Also, the pointer on the format helped a lot. I don't recall seeing a reference to that in the docs, or if there was it didn't stand out.
I had to manually add these
or
Did I miss a step somewhere? |
Beta Was this translation helpful? Give feedback.
-
Hello, These are the scripts that we use <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.1/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon@1.28.1"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@1.0.0"></script> Regarding the date formats. I agree; we should mention them in the documents to prevent future confusion. Also, it would be good if we could add mappings for .NET date formats. Similar to what we have on the DatePicker component. But that would probably be a breaking change and not an easy task. |
Beta Was this translation helpful? Give feedback.
-
I might be a little dense, but I'm having issues presenting dates in a chart in the desired format. The graph is displaying the full format "yyyy-MM-ddThh:mm:ss" format. I prefer just the "yyyy-MM-dd" format.
What do I need to change in LineChartOptions to present it in a custom format?
Beta Was this translation helpful? Give feedback.
All reactions