Hey folks, brand new to Observable but working on a project utilizing D3. I have a line chart that plots 3 different lines. I’ve got the X axis working properly but the Y axis only shows a partial amount of the range needed to plot all of the values on the visible graph. All 3 of the lines are pulling data from arrays that have identical properties. I’m using the following code in my DrawChart
component to establish min and max values for the Y axis:
const [minY, maxY] = emptyChart
? [0, 100000]
: d3.extent<ChartPoint, number>(
data[0].points,
(point) => point.pointTotal
);
// @ts-ignore
const yScale = d3
.scaleLinear()
.domain([minY!, maxY!])
.range([height - margin, 0])
.nice();
Here is the code in the rendering component for the chart:
<DrawChart
data={[
{
name: "Revenue",
color: "#2E99E6",
points:
sortedRevenueByDate?.map((points) => ({
date: new Date(points?.date as string),
pointTotal: points.pointTotal as number,
cum: points.cum as number,
ytd: points.ytd as number,
})) || [],
},
{
name: "Profit",
color: "#4CBF4C",
points:
sortedProfitByDate?.map((points) => ({
date: new Date(points.date as string),
pointTotal: points.pointTotal as number,
cum: points.cum as number,
ytd: points.ytd as number,
})) || [],
},
{
name: "Expenses",
color: "#CC493D",
points:
sortedExpensesByDate?.map((points) => ({
date: new Date(points.date as string),
pointTotal: points.pointTotal as number,
cum: points.cum as number,
ytd: points.ytd as number,
})) || [],
},
]}
/>
If I only plot a single line from the 3, then I have the correct Y axis range showing for the chart. But when I allow multiple lines to be plotted then the range seems to default to only the first line in my data
object. Can someone shine some light on this for me?
Thanks so much!