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

[Bug]: No theme colors when using window.renderChart #103

Open
anstadnik opened this issue Nov 15, 2023 · 4 comments
Open

[Bug]: No theme colors when using window.renderChart #103

anstadnik opened this issue Nov 15, 2023 · 4 comments

Comments

@anstadnik
Copy link

Describe the bug

When using window.renderChart, there are no theme colors.

Relevant errors (if available)

No response

Steps to reproduce

Plot a graph using window.renderChart.

Expected Behavior

First graph should use theme colors.

Additional context

image

Code

type: line
    labels: [Monday,Tuesday,Wednesday,Thursday,Friday]
    series:
        - title: Title 1
          data: [1,2,3,4,5]
        - title: Title 2
          data: [5,4,3,2,1]
        - title: Title 3
          data: [8,2,5,-1,4]

```dataviewjs
const chartData = {
  type: 'line',
  data: {
    labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
    datasets: [
      {
        label: 'Title 1',
        data: [1, 2, 3, 4, 5],
      },
      {
        label: 'Title 2',
        data: [5, 4, 3, 2, 1],
      },
      {
        label: 'Title 3',
        data: [8, 2, 5, -1, 4],
      }
    ]
  },
};

window.renderChart(chartData, this.container);


### Operating system

macOS
@tanchao90
Copy link

I have the same problem and hope to fix it soon.

const data = dv.current()

const chartData = {
    type: 'line',
    data: {
        labels: ['2023-01', '2023-02', '2023-03', '2023-04'],
        datasets: [{
            label: 'Kobe',
            data: [60, 70, 80, 90]
        },{
            label: 'Jordan',
            data: [90, 80, 80, 70]
        }]
    }
}

window.renderChart(chartData, this.container);
image

@anstadnik
Copy link
Author

Apparently that feature only works for chart code block, so as a workaround I used

dv.paragraph(`\`\`\`chart
...
\`\`\``);

@tanchao90
Copy link

I hope author can upgrade chartjs to 4.4.0 to support the feature:

Default color palette

image

@kimobot
Copy link

kimobot commented Apr 4, 2024

A little late to the party, but I came across the same issue with the axis labels on my radar graphs and found a solution. After a bit of digging into ChartJS, I found that it's possible to specify colours manually. Using your example:

image

```dataviewjs
const chartData = {
  type: 'line',
  data: {
    labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
    datasets: [
      {
        label: 'Title 1',
        data: [1, 2, 3, 4, 5],
        backgroundColor: [
          'rgba(255, 99, 132, 0.2)'
        ],
        borderColor: [
          'rgba(255, 99, 132, 1)'
        ],
        borderWidth: 1,
      },
      {
        label: 'Title 2',
        data: [5, 4, 3, 2, 1],
      },
      {
        label: 'Title 3',
        data: [8, 2, 5, -1, 4],
      }
    ]
  },
};
window.renderChart(chartData, this.container);

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

3 participants