Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple series on a line chart create overlapping x-axis #576

Open
argium opened this issue Feb 4, 2025 · 0 comments
Open

Multiple series on a line chart create overlapping x-axis #576

argium opened this issue Feb 4, 2025 · 0 comments

Comments

@argium
Copy link

argium commented Feb 4, 2025

I'm having trouble explaining this so I'll try use visuals and code. I'm creating a simple chart where there's a single x-axis (time) and y-axis (decimal). The line has multiple disconnected segments that each need to be coloured differently. Each segment is on the same x-axis but at different, non-overlapping values.

This is what the end result should look like using Excel:

Image

I'm trying to recreate this using ApexCharts. This is a basic example of the problem:

Data = new ChartData();
Data.Series.Add("Series1", [new(DateTime.Parse("2024-01-01"), 10), new(DateTime.Parse("2024-01-02"), 15), new(DateTime.Parse("2024-01-03"), 20)]);
Data.Series.Add("Series2", [new(DateTime.Parse("2024-01-04"), 20), new(DateTime.Parse("2024-01-05"), 15), new(DateTime.Parse("2024-01-06"), 10)]);

ChartOptions ??= new ApexChartOptions<DataPoint>();
ChartOptions.Chart.Width = 900;
ChartOptions.Chart.Height = 500;
    <ApexChart TItem="DataPoint" Title="Report" Options="@(ChartOptions)">
    @foreach (var series in Data.Series)
    {
        <ApexPointSeries TItem="DataPoint"
                            Items="@(series.Value)"
                            Name="@(series.Key)"
                            SeriesType="SeriesType.Line"
                            XValue="e => e.Time"
                            YValue="e=> e.Value"
                            />
    }
    </ApexChart>

Expected
There is a single x-axis from range(min(series1), max(series2)), and the two series are plotted one after the other along it.

Image

Actual

Each series has its own x-axis which are overlayed on top of eachother.

Image


If I combine all the values into a single ApexPointSeries, the x-axis is except:

  1. Is there a way to colour sections of the line series differently?
  2. The sharp vertical lines between every segment are incorrect.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant