I thought I would have a go at seeing if chatGPT could help me write a simple column chart library to present values historically on a webpage. The result was perhaps a little more involved than I wanted, and took about 4 days in the end, mostly due to all the additional options I thought should be there, and some sizing fine tuning - but this was the result.
The point of this library was
Also see jsfiddle.net to run an editable demo.
To use mf-chart-column, simply place a div on your html including the data and the controls as attributes for the div.
html
if you wanted to just pass in values from a start date, then use data
and data-start
attributes:
html
then define your chart height using css (or an inline div style)
css
and include the library in your head
html
Alternatively, if you need to trigger a chart generation after page load then you can use the mfColumnChart(divElem);
javascript command
In addition to the data
attribute, you can use the following attributes on your div
:
data-start | start date (yyyy-mm-dd) for data of type n,n,n,... |
data-prefix | text added to before a value seen on the vertical axis |
data-units | text added to after the value when presented in a column mouseover |
data-controls | semi-column separated list of chart painting instructions to customize the chart. See Chart Instructions below |
e.g.
The following instructions are supported by the data-controls attribute, each separated by a semi-colon, e.g. <div ... data-controls='chartAreaColorBg=black;xAxisLineColorCd=white;....'>
Control | Notes |
---|---|
trace | (T |
help | (T |
chartAreaColorBg | (color code) Set the background color of the chart canvas (e.g. red, #ff0000, etc) , e.g. red, #fff, green, etc |
columnColorCd | (color code) Set the color of the chart columns (e.g. red, #ff0000, etc) ; default=#aeaec3 |
columnValues | (T |
columnValuesChartMinWidth | (integer) Set the minimum width of chart that supports chart values; charts thinner than this will not show chart values at the end of the plotted column ; default=0 |
columnValuesColorCd | (color code) Set the color of column values found at the top |
columnValuesFont | (font-size and name) Set the font for column values if columnValues=T ; default=12px Arial |
columnValueHoverFont | (font-size and name) Set the font name and size of the text in a column value hover ; default=12px Arial |
columnValueHoverFontColorCd | (color code) Set the color the text in a column value hover ; default=black |
columnValuesLabelYOffset | (integer) Y position adjustment for column value display if columnValues=T ; default=10 |
columnWidthMax | (integer) Overrides the maximum width of columns on the chart |
columnWidthMin | (integer) Overrides the minimum width of columns on the chart; warning: this settings can cause columns of overlap. |
hoverColumnNTips | (T |
marginLeft | (integer) margin left for the chart ; default=15 |
marginRight | (integer) margin right for the chart ; default=5 |
marginBottom | (integer) margin bottom for the chart ; default=4 |
marginTop | (integer) margin top for the chart (note, the axis labels will want to nudge the top here, so the font size is used to account for this) |
plotAreaBox | (T |
plotAreaBoxColorCd | (color code) Adjust the plot area box color ; default=white |
plotAreaBoxLineWidth | (integer) Adjust the plot area box line width ; default=1 |
plotAreaColorBg | (color code) Adjust the color of the plot area background , e.g. red, #fff, green, etc' |
plotPaddingLeft | (integer) Adjust the left |
plotPaddingRight | (integer) Adjust the right |
xAxisLine | (T |
xAxisLineColorCd | (color code) Adjust the x-axis line color ; default=black |
xAxisTickMarks | (T |
xAxisTickMarksColorCd | (color code) Adjust the color of the tick marks on the horizontal x-axis showing the column dates ; default=black |
xAxisValueColorCd | (color code) Adjust the color of the date values on the horizontal x-axis ; default=black |
xAxisValueFont | (font-size and name) Set the font used on the date axis values ; default=12px Arial |
yAxisFont | (font-size and name) Set the font used on the vertical value axis values ; default=12px Arial |
yAxisGridColorCd | (color code) Adjust the color of the vertical values on the y-axis ; default=#eaeaef |
yAxisGridLines | (T |
yAxisGridLinesOverlay | (T |
yAxisLabelPaddingLeft | (integer) Pad the left of the y-axis value labels on the left of the chart ; default=0 |
yAxisLabelPaddingRight | (integer) Pad the right of the y-axis value labels on the left of the chart - moves these labels away from the y-axis line ; default=0 |
yAxisLine | (T |
yAxisScale | (integer) Divide the values shown on the leftside y-axis by this, e.g. yAxisScale=1000000 and yAxisScaleTx=m will divide all numbers by 1,000,000 and add "m" to the label so that "1,500,000" would become "1.5m"; set to "AUTO" to have the library compute the most appropriate values to be shown (k or m) ; default=1 |
yAxisScaleTx | (text) Add text to the right of each y-axis value, e.g. "k" or "m" |
yAxisScalePrefix | (text) Add text to the left of each y-axis value, e.g. "GBP" |
yAxisTickCountMin | (integer) Set the minimum number of ticks that the logic should use to find an appropriate y-axis tick step ; default=3 |
yAxisTickCountMax | (integer) Set the maximum number of ticks that the logic should use to find an appropriate y-axis tick step ; default=6 |
yAxisTickValueColorCd | (color code) Set the color of the vertical y-axis values on the left of the chart ; default=black |
yAxisTickWidth | (integer) Set the width of small line-ticks found to the left of the yAxisLine ; default=4 |
Also see
articles/Implementing-a-Monaco-Editorsquarearticles/iConnectionTestsquarearticles/image-zoomingsquarearticles/javascript-camerasquarearticles/list-editsquarearticles/minifierssquarearticles/opayosquarearticles/table-drag-sortersquarearticles/typewatchsquareprojects/MFCalendarPopupsquareprojects/MFChartColumnsquareprojects/MFColorPickersquareprojects/MFColorPickerBasicsquareprojects/MFColumnDataBarsquareprojects/MFColumnGradientsquareprojects/MFCropCornerUIsquareprojects/MFFloatawayMsgsquareprojects/MFPanelssquareprojects/MFSelectorsquareprojects/MFShowConsolesquare