Blazor ApexCharts – 无法在X轴上显示重复的数值

huangapple go评论76阅读模式
英文:

Blazor ApexCharts - Cannot show the repeated values on XAxis

问题

你好,你想让图表显示重复的日期而不仅仅是第一项。你可以通过设置ApexCharts的xaxis配置来实现。在你的View中的<ApexChart>标签中添加以下行:

XAxis=&quot;@(new { categories = datas.Select(d =&gt; d.date).ToArray() })&quot;

希望这能帮到你!

英文:

I am currently using ApexCharts to generate charts for analysis.

Is it possible to repeat items on the XAxis?

This is what I got:

Blazor ApexCharts – 无法在X轴上显示重复的数值

This is what I want:

Blazor ApexCharts – 无法在X轴上显示重复的数值

View:

&lt;ApexChart TItem=&quot;DataItem&quot; Title=&quot;Measurement(mm)&quot;&gt;
    &lt;ApexPointSeries    TItem=&quot;DataItem&quot;
                        Items=&quot;datas&quot;
                        Name=&quot;Measurement&quot;
                        SeriesType=&quot;SeriesType.Line&quot;
                        XValue=&quot;@(e=&gt;e.date)&quot;
                        YValue=&quot;@(e=&gt;e.value)&quot; 

    /&gt;
&lt;/ApexChart&gt;

Code:

public class DataItem
{
    public string date { get; set; } = string.Empty;
    public int value { get; set; }
    public int id { get; set; }
}

List&lt;DataItem&gt; datas = new List&lt;DataItem&gt; 
{
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 3 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 4 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 3 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 5 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 5 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 6 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 7 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 9 },
    new DataItem { date = &quot;2023-03-20 01:39:03&quot;, value = 13 }
};

I want the graph to show the repeated date instead of just the first item.

How can I set the configs? Thanks!

答案1

得分: 1

I will only provide translations of the text you provided, excluding code and without answering translation questions. Here is the translated text:

相信这个错误与图表不会在重复的X轴值上绘制类似,尽管报告的问题是绘制双线图。

建议报告此问题,以便存储库所有者了解问题并修复它。

一个快速的解决方法是应用以下配置:XAxisType="XAxisType.Numeric"

演示

Blazor ApexCharts – 无法在X轴上显示重复的数值

英文:

Believe that this bug is similar to Chart won't draw on Duplicate X-Axis value although the reported issue is for drawing a 2-line chart.

It is recommended to report this issue so that the repository owner understands the issue and fixes it.

A quick fix is applying the configuration: XAxisType=&quot;XAxisType.Numeric&quot;.

&lt;ApexChart TItem=&quot;DataItem&quot; Title=&quot;Measurement(mm)&quot; XAxisType=&quot;XAxisType.Numeric&quot;&gt;
    &lt;ApexPointSeries TItem=&quot;DataItem&quot;
                     Items=&quot;datas&quot;
                     Name=&quot;Measurement&quot;
                     SeriesType=&quot;SeriesType.Line&quot;
                     XValue=&quot;@(e=&gt; e.date)&quot;
                     YValue=&quot;@(e=&gt;e.value)&quot; /&gt;
&lt;/ApexChart&gt;

> Demo

Blazor ApexCharts – 无法在X轴上显示重复的数值

huangapple
  • 本文由 发表于 2023年4月13日 14:31:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76002318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定