cokicoki free asked 5 years ago


Expected behavior

I will like to make some Charts & Minimalist Charts for my web in dynamically. So my question is how to make the charts component that can change the value overtime in real-time dynamically based on the database I have in MySql Server. If my database change, the charts values also can change in real-time.

Would you please help and advise me step by step to achieve that and what are the requirement should I follow? I am appreciated your kind assistance. Thank you very much.

Actual behavior

Right now the charts and minimalist-chart that I have are just static.

Resources (screenshots, code snippets etc.)


Jakub Chmura staff answered 5 years ago


Hi @cokicoki,

In the examples you have written, you must use the same code as in the sample I wrote above.

You need to use state:

 state = {
    yourVariableName: 10
  };

Function to change the state.

  handleChange = e => {
    this.setState({
      yourVariableName: e.target.value
    });
  };

Charts props:

percent={this.state.yourVariableName}

That's all you need to do to make your charts dynamic.

Best Regards,

Kuba


cokicoki free commented 5 years ago

Hi, Kuba. Thank you for your advice.


Jakub Chmura staff commented 5 years ago

No problem.

If there is anything else I could do for you do not hesitate to ask me. I'll be happy to help you.

Best Regards,

Kuba


cokicoki free answered 5 years ago


Hi Kuba,

Thanks so much for your reply and minimalist chart snippet given.

Would you mind and please also give the other snippet charts for : Line chart, Radar chart, Bar chart, Polar Area Chart, Pie Chart, Doughnut Chart as I use them a lot on my web.

I wish that all my charts can perform dynamically and real-time based on the database I have.Thank you very much.


Jakub Chmura staff answered 5 years ago


Hi @cokicoki,

Unfortunately, I can not help you with your database but I wrote a simple snippet to show you how to change dynamically value of the MDBSimpleChart. You should only replace my variable to your data from MySql.

import React from 'react';
import {
  MDBContainer,
  MDBRow,
  MDBCol,
  MDBSimpleChart,
  MDBInput
} from 'mdbreact';

class ChartsPagePro extends React.Component {
  state = {
    variable: 10
  };

  handleChange = e => {
    console.log(e.target.value);
    this.setState({
      variable: e.target.value
    });
  };

  render() {
    return (
      <MDBContainer>
        <h3 className='mt-5'>Minimalistic charts</h3>
        <div style={{ marginTop: '100px' }}>
          <MDBContainer>
            <MDBRow className='text-center'>
              <MDBCol sm='4'>
                <MDBSimpleChart
                  width={100}
                  height={100}
                  strokeWidth={3}
                  percent={this.state.variable}
                  strokeColor='#4FB64E'
                  labelFontWeight='300'
                  labelColor='#000'
                />
                <MDBInput type='number' onChange={this.handleChange}></MDBInput>
              </MDBCol>
            </MDBRow>
          </MDBContainer>
        </div>
      </MDBContainer>
    );
  }
}

export default ChartsPagePro;

If there is anything else I could do for you do not hesitate to ask me. I'll be happy to help you.

Best Regards,

Kuba



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.22.0
  • Device: PC
  • Browser: Mozilla Firefox
  • OS: windows 7
  • Provided sample code: No
  • Provided link: No