-
I want to make a monthly bar chart. My data structure as below
{
marks: [
Plot.barY(sampleData, {
x: "month",
y: "value",
sort: null,
}),
Plot.ruleY([0]),
],
x: {
label: "Month",
},
} The final result as shown below, the months are sorted alphabetically. I tried multiple ways to customize the sort function but it doesn't work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Two suggestions: the first is to read the dates first as JavaScript dates, for example with d3.utcParse, and use an interval to recreate the bars as rect marks. The second is to keep them as strings (and ordinal values, represented by bars), but transform them so that they are ordered naturally by time. |
Beta Was this translation helpful? Give feedback.
Two suggestions: the first is to read the dates first as JavaScript dates, for example with d3.utcParse, and use an interval to recreate the bars as rect marks. The second is to keep them as strings (and ordinal values, represented by bars), but transform them so that they are ordered naturally by time.
See the two possibilities at https://observablehq.com/@recifs/reading-dates